37

I have just converted a project to VS2010 and I now starting to see Exceptions in my software in IntelliTrace.

One such Exception is 'Application identity is not set', this occurs whenever my software see's something like

string m_AppPath = Application.UserAppDataPath;

This isn't a problem as the AppDataPath returns correctly, I'm just wondering why this happens.

The code is in the Main function of Program.cs (if that makes a difference), once out of the Program.cs file and into MainWindow.cs the code works.

My main issue is that I setup Logging prior to the application starting. Any help appreciated as searching the web doesn't really help.

Paul

Paul Talbot
  • 1,583
  • 1
  • 14
  • 28

3 Answers3

65

I found that this problem exists only if you untick "Just My Code" under debug options.

Carlos
  • 5,991
  • 6
  • 43
  • 82
  • 2
    Perfect answer! I've been plagued by this error on and off for the last month, and this tip finally fixed it! – Contango Sep 16 '15 at 10:41
  • Solves the issue, but what does this option do? It hides me more exceptions, not only this one... – miguelmpn Jul 28 '17 at 11:22
  • 1
    So, if `this problem exists only if you untick "Just My Code" `, then there should not be a problem if "Just My Code" is ticked, right? Well, in a VS2017 project, I have "Just My Code" ticked, and I still get this error when I start debugging. – sdbbs Jul 17 '19 at 11:09
  • Sorry to hear that. It's been a long while since I answered this, so pretty hard for me to jump back in and help you. Different firm, different stack. – Carlos Jul 17 '19 at 20:19
27

If the problem is occuring in debugging you can first check if the debugger is attached before accessing any application settings:

If System.Diagnostics.Debugger.IsAttached then
       Me.Text = "Debug Mode"
Else 
       Me.Text = "Version " & My.Application.Deployment.CurrentVersion.ToString
End If
gazamatazzer
  • 430
  • 6
  • 14
3

If this is a ClickOnce application being debugged, another option is to check the System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed setting.

PeterX
  • 2,713
  • 3
  • 32
  • 42