是什么导致 WPF 应用程序中出现 InvalidDeploymentException?

发布于 2024-10-11 22:45:50 字数 780 浏览 0 评论 0原文

我开发了一个 WPF 应用程序,当我在调试模式下启动它时,我在输出中看到以下内容:

“WpfApplication1.vshost.exe”(托管 (v2.0.50727)): 已加载 'C:\ WINDOWS \程序集\ GAC_MSIL \ System.Deployment \ 2.0.0.0__b03f5f7f11d50a3a \ System.Deployment.dll', 符号已加载。第一次机会 类型异常 'System.Deployment.Application.InvalidDeploymentException' 发生在System.Deployment.dll中 附加信息:应用 身份未设置。

如果我在另一个 WPF 应用程序中使用此应用程序中的控件,则输出中会有 7 条此类消息。尽管如此,该应用程序运行良好。

您能解释一下抛出这些异常的原因吗?我发现方法 ApplicationDeployment.get_CurrentDeployment 引发了它们。 MSDN 中写道,当“您尝试从非 ClickOnce 应用程序调用此静态属性”时,会出现此异常。我不明白这意味着什么。

我发现类似的帖子 InvalidDeploymentException - 应用程序身份未设置,但没有答案对于这个问题。

I developed a WPF application and when I launch it in the debug mode I see the following in the output:

'WpfApplication1.vshost.exe' (Managed
(v2.0.50727)): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll',
Symbols loaded. A first chance
exception of type
'System.Deployment.Application.InvalidDeploymentException'
occurred in System.Deployment.dll
Additional information: Application
identity is not set.

If I use a control from this application in another WPF application, there are 7 such messages in the output. Nevertheless, the application works fine.

Could you explain the reason why these exceptions thrown? I found that the method ApplicationDeployment.get_CurrentDeployment raises them. In the MSDN it is written that this exception arises when “You attempted to call this static property from a non-ClickOnce application.” I can’t understand what it means.

I found similar post InvalidDeploymentException - Application identity is not set but there is no answer to this question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2024-10-18 22:45:51

这是“第一次机会异常”,这意味着调试器只是通知您抛出了异常,而不是未处理异常。

.NET Framework 在内部抛出并捕获该异常 - 调试器告诉您它发生在 System.Deployment.dll 的某些代码中。当尝试访问用户/网络信息时会引发异常,但底层代码会在异常发生时捕获异常并自动恢复执行。你对此无能为力,而且相对无害。

您很可能尝试检索当前用户的 AppData 路径,在这种情况下,框架需要确定您的应用程序是普通应用程序还是 ClickOnce 应用程序,以便返回正确的路径。如果您是 ClickOnce 应用程序,则仅返回正确的数据。否则,将引发异常,该异常将被框架捕获,并假设您的应用程序不是 ClickOnce 应用程序,从而导致返回标准用户路径。

应用程序运行时会引发和处理许多异常。除非不加以处理,否则不会造成任何伤害。如果这确实让您烦恼,您可以自定义调试器通知您的异常。例如:

  1. 从“调试”菜单打开“异常”窗口。
  2. 展开“公共语言运行时异常”-> “系统.部署.应用程序”。
  3. 取消选中“System.Deployment.Application.InvalidDeploymentException”旁边的框。

This is a "first chance exception", which means the debugger is simply notifying you that an exception was thrown, rather than that one was unhandled.

The .NET Framework is throwing and catching that exception internally—the debugger tells you that it occurs in some code in System.Deployment.dll. The exception is raised when an attempt is made to access user/network information, but the underlying code is catching the exception when it occurs and automatically resuming execution. There's nothing you can do about it, and it's relatively harmless.

You are most likely attempting to retrieve the AppData path for the current user, in which case the Framework needs to determine if your application is a normal app or a ClickOnce app in order to return the correct path. If you are a ClickOnce app, the correct data is simply returned. Otherwise, an exception is thrown, which is caught by the Framework and the assumption is made that your application is not a ClickOnce app, causing the standard user path to be returned instead.

There are a number of exceptions that are thrown and handled while an application is running. There's no harm unless they're unhandled. If this really bugs you, you can customize the exceptions about which the debugger informs you. For example:

  1. Open the Exceptions window from the Debug menu.
  2. Expand "Common Language Runtime Exceptions" -> "System.Deployment.Application".
  3. Uncheck the box next to "System.Deployment.Application.InvalidDeploymentException".
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文