-
Oct 27th, 2017, 02:20 AM
#1
Thread Starter
New Member
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!
-
Oct 27th, 2017, 05:35 AM
#2
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:
Imports System.Runtime.InteropServices Imports Microsoft.VisualBasic.ApplicationServices Namespace My ' The following events are available for MyApplication: ' Startup: Raised when the application starts, before the startup form is created. ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. ' UnhandledException: Raised if the application encounters an unhandled exception. ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. Partial Friend Class MyApplication Private Enum ProcessDpiAwareness DpiUnaware = 0 SystemDpiAware = 1 PerMonitorDpiAware = 2 End Enum Const OK As Integer = &H0 Const INVALID_ARG As Integer = &H80070057 Const ACCESS_DENIED As Integer = &H80070005 <DllImport("shcore.dll")> Private Shared Function SetProcessDpiAwareness(value As ProcessDpiAwareness) As Integer End Function Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup Select Case SetProcessDpiAwareness(ProcessDpiAwareness.SystemDpiAware) Case OK MessageBox.Show("DPI aware") Case INVALID_ARG MessageBox.Show("Invalid argument") Case ACCESS_DENIED MessageBox.Show("Access denied") End Select End Sub End Class End Namespace
That solution was based on this thread:
http://www.vbforums.com/showthread.p...warenes-in-VB6
-
Oct 27th, 2017, 07:49 AM
#3
Thread Starter
New Member
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!
-
Oct 27th, 2017, 09:17 AM
#4
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.
-
Oct 27th, 2017, 05:14 PM
#5
Thread Starter
New Member
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!
-
Aug 29th, 2024, 05:47 PM
#6
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|