Results 1 to 6 of 6

Thread: Application is Improperly Formatted - DPI Aware/Manifest Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    3

    Question Application is Improperly Formatted - DPI Aware/Manifest Error

    Hi there,

    I am on VB .Net 2017 with .Net 4.6.2.

    I wrote a relatively straight forward application that incorporates the need for taking a full screen screenshot. The screen resolution it was pulling was not accurate, and I discovered that I need to make my application DPI Aware in order for my screenshot to get the right resolution to take a screenshot of the entire screen.

    I added an app.manifest to the project, and uncommented this section:

    Code:
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        </windowsSettings>
      </application>
    Doing so corrected the screen resolution issue I was having and my application works perfectly. However, now when I Publish my application, the setup program pops up a window stating "Cannot continue. The application is improperly formatted. Contact the application vendor for assistance."

    If I re-comment that section from the app.manifest, then everything is fine, except the resolution is still incorrect. So the app.manifest existing in itself doesn't appear to be an issue. It is specifically uncommenting that particular section that is causing problems.

    I'm at a loss. This is my first VB project since VB6 was all the rage god knows how long ago, so I don't really have the know-how to troubleshoot this myself.

    I found a post somewhere on Google in which someone suggests declaring the DPI Awareness through code rather than manifest, and they give a half-example of "something like this," without completing the code nor explaining where/how to use it.

    Any ideas how I can get around this issue?

    Thank you so much!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,932

    Re: Application is Improperly Formatted - DPI Aware/Manifest Error

    From what I've read, you cannot use that manifest entry, among others, with a ClickOnce application. Click the 'View Application Events' button on the Application page of the project properties and then try code like this:
    VB.NET Code:
    1. Imports System.Runtime.InteropServices
    2. Imports Microsoft.VisualBasic.ApplicationServices
    3.  
    4. Namespace My
    5.     ' The following events are available for MyApplication:
    6.     ' Startup: Raised when the application starts, before the startup form is created.
    7.     ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    8.     ' UnhandledException: Raised if the application encounters an unhandled exception.
    9.     ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
    10.     ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    11.  
    12.     Partial Friend Class MyApplication
    13.  
    14.         Private Enum ProcessDpiAwareness
    15.             DpiUnaware = 0
    16.             SystemDpiAware = 1
    17.             PerMonitorDpiAware = 2
    18.         End Enum
    19.  
    20.         Const OK As Integer = &H0
    21.         Const INVALID_ARG As Integer = &H80070057
    22.         Const ACCESS_DENIED As Integer = &H80070005
    23.  
    24.         <DllImport("shcore.dll")>
    25.         Private Shared Function SetProcessDpiAwareness(value As ProcessDpiAwareness) As Integer
    26.         End Function
    27.  
    28.         Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
    29.             Select Case SetProcessDpiAwareness(ProcessDpiAwareness.SystemDpiAware)
    30.                 Case OK
    31.                     MessageBox.Show("DPI aware")
    32.                 Case INVALID_ARG
    33.                     MessageBox.Show("Invalid argument")
    34.                 Case ACCESS_DENIED
    35.                     MessageBox.Show("Access denied")
    36.             End Select
    37.         End Sub
    38.  
    39.     End Class
    40.  
    41. End Namespace
    That solution was based on this thread:

    http://www.vbforums.com/showthread.p...warenes-in-VB6
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    3

    Re: Application is Improperly Formatted - DPI Aware/Manifest Error

    Thanks jmcilhinney!

    That seems to have fixed the problem of being able to install.

    Now I have a new problem: After install, it won't run. It doesn't give any errors or feedback. The icon simply never shows up in the task bar and nothing happens.

    But during development I can run it without any issues.

    I don't know if it's related to the code - late for a meeting as it is so don't have time to retry it without the new code inserted to make sure that I didn't screw something else up somewhere in all this trial-and-erroring. But I'm pretty sure that everything else is in order...

    If you have any thoughts, please share. Thanks!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,932

    Re: Application is Improperly Formatted - DPI Aware/Manifest Error

    I wonder whether that API function requires some sort of permission that your app doesn't have. I'd add some logging and event handling to that Startup event to see whether it's getting in and out.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    3

    Re: Application is Improperly Formatted - DPI Aware/Manifest Error

    I don't actually know what I did wrong. I took out the DPI Aware code entirely and went to bare-basics on my application. It still didn't want to run. I couldn't get any MsgBox's to pop up no matter how early I placed them in the application startup.

    So, since my application is literally 3 buttons and a Sub containing my "take screen shot and save to a calculated location and filename based on the number of seconds since midnight and which button was pressed" code, I just started a brand new project, recreated the form, pasted the code, and now it works flawlessly!

    I must have bastardized my project somehow when trial-and-erroring my way through this and broken something inadvertently.

    Thanks for your help! I really appreciate it!

  6. #6
    New Member
    Join Date
    Aug 2024
    Posts
    1

    Re: Application is Improperly Formatted - DPI Aware/Manifest Error

    Thank you jmcilhinney. It worked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width