What causes an InvalidDeploymentException in a WPF

2019-02-08 02:07发布

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.

1条回答
相关推荐>>
2楼-- · 2019-02-08 02:21

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".
查看更多
登录 后发表回答