vb.net 例外:未设置应用程序标识
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19428462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception: Application identity is not set
提问by ElektroStudios
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
异常信息: Application identity is not set
The exception occurs in debugging and also in release, in VS2012, targeting FW 4.0 in a Winforms.
异常发生在调试和发布中,在 VS2012 中,针对 Winforms 中的 FW 4.0。
I've read here: Application identity not set Exception
我在这里读过:应用程序标识未设置异常
...And also here: InvalidDeploymentException - Application identity is not set
...还有这里:InvalidDeploymentException - 未设置应用程序标识
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.
原因只是我不想手动禁用异常并记住为我存储的每个项目和未来的项目执行此操作,我想以自然的方式解决此问题。
回答by Carlos Landeras
Is it a ClickOnce application? It is network deployed? Are you debugging? That would not work in debug mode.
它是 ClickOnce 应用程序吗?是网络部署吗?你在调试吗?这在调试模式下不起作用。
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.
由于它不是网络部署的应用程序,我会检查该应用程序之前是否已启动保存用户设置或在注册表中建立一个值。
回答by Steve
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 中:
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!
如果您不创建单击一次部署,请不要使用这些类!

