What causes an InvalidDeploymentException in a WPF application?

21,065

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".
Share:
21,065

Related videos on Youtube

Kirill Lykov
Author by

Kirill Lykov

Software Engineer

Updated on July 09, 2022

Comments

  • Kirill Lykov
    Kirill Lykov almost 2 years

    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.

  • Kirill Lykov
    Kirill Lykov over 13 years
    ok, and how can I check if my application ClickOnce or normal one and if it is normal, to set in the correct path?
  • Cody Gray
    Cody Gray over 13 years
    @Kirill: Apologies if my answer wasn't clear. I'm saying that the .NET Framework does all of this internally. It's not something that you're doing, or even that you have any control over. That's simply how it determines whether or not your application is ClickOnce or normal. You can't set it yourself. Remember, the .NET Framework is a giant library of code that is running alongside your own code to handle lower-level functions.