'Application identity is not set' with ClickOnce

10.1k views Asked by At

I'm scratching my head at this issue and have spent quite some time looking into it. Every question I've looked at based on this issue looks to be with debugging (I also have this issue with debugging). However, that's not the reason behind this.

In my application I gave the user the option to create a shortcut so that the application will run automatically in startup (I found this a much easier approach than editing the registry).

string copyPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\";
using (StreamWriter writer = new StreamWriter(copyPath + "\\" + "ZApp.url"))
{
    string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
    writer.WriteLine("[InternetShortcut]");
    writer.WriteLine("URL=file:///" + app);
    writer.WriteLine("IconIndex=0");
    string icon = app.Replace('\\', '/');
    writer.WriteLine("IconFile=" + icon);
    writer.Flush();
}

This code works great. However, whenever the application checks for an update in the background, it throws the Application identity is not set error.

This is the code that I use for checking for an update:

ApplicationDeployment deploy = ApplicationDeployment.CurrentDeployment; //<- Error thrown here
UpdateCheckInfo update = deploy.CheckForDetailedUpdate();

Again, it works great if I start the application using the icon that ClickOnce places on my desktop, however not great if I use the shortcut icon that my code creates in the startup folder. Is there a way for me to programmatically get round this?

1

There are 1 answers

9
Stefan Over On BEST ANSWER

The deployment state is the cause of the error. As already explained by rudolf_franek, the application is not network deployed. Applying the check before accessing the CurrentDeployment will make your application more safe:

if (ApplicationDeployment.IsNetworkDeployed)
{
    // accessing the CurrentDeployment won't throw an exception
    var deploy = ApplicationDeployment.CurrentDeployment;
}

But to resolve the problem causing the ApplicationDeployment.IsNetworkDeployed being false, you should take a look at this MSDN forum post. tl;dr: Creating a shortcut referencing the *.exe file will make the application run as stand-alone.

The solution:
You should create a proper shortcut, where you reference the application deployment manifest (a.k.a. *.application file). This should do the trick.