问题
I'm having this exception when trying to use any of the Deployment members like for example I try in this simple code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MsgBox(If(My.Application.Deployment.IsFirstRun, "Yes", "No"))
End Sub
End Class
Exception message: Application identity is not set
The exception occurs in debugging and also in release, in VS2012, targeting FW 4.0 in a Winforms.
I've read here: Application identity not set Exception
...And also here: InvalidDeploymentException - Application identity is not set
I don't remember how to deactivate the exception checking in the project settings but anyways there is a way to avoid this exception without manually disabling exceptions?
The reason is just I don't want to manually disable exceptions and remember to do it for each of my stored and future projects, I want to fix this problem in a natural way.
回答1:
Is it a ClickOnce application? It is network deployed? Are you debugging? That would not work in debug mode.
If you are debugging, use this to test:
If Not System.Diagnostics.Debugger.IsAttached Then
firstRun = My.Application.Deployment.IsFirstRun
End If
-
As it is not a network deployed application, I would check if the application has been previously launched saving a user settings or establishing a value in the registry.
回答2:
The method that you are calling is only available with a click-once deployed application. You must surround all deployment code in an IF like this:
If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
...Your code here
End If
Or else it will error.
This does make it hard to debug your code, because it will only run when deployed, but you should create a test application with message boxes to see what is happening.
If you are not creating a click-once deployment, dont use these classes!
来源:https://stackoverflow.com/questions/19428462/exception-application-identity-is-not-set