简体   繁体   中英

ClickOnce: “Application identity is not set”

I have a pretty old Windows Forms application for which I'm currently trying to build a ClickOnce installer.

Everything is fine except that any attempt to access ApplicationDeployment.CurrentDeployment from within the application results in:

Application identity is not set.

I found a lot of posts of this kind on web and particularly here on Stack Overflow, but people run their application under a debugger or simply not network-deployed local versions.

I emphasize that in my case the application is network-deployed (available offline). I'm running it by clicking the desktop icon created by ClickOnce installer. Update works fine (tried to publish an update to make sure it works).

Nevertheless, ApplicationDeployment.CurrentDeployment is not accessible.

What I'm doing wrong?

In fact, I'm only trying to read the application's version as it appears in the "Programs and Features" applet. Is there a way to read this information without using of ClickOnce API, for example, directly from the registry (I understand that it is not nice).

The code is very simple:

[STAThread]
static void Main(string[] argv)
{
System.Windows.Forms.MessageBox.Show(ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()); // Crash here
DoSomethingUseful();
}

I have done this using a property and bound its value in XAML directly. I am using WPF, but I hope this helps.

private string _verSion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
public string verion
{
    get
    {
        return _verSion;
    }
    set
    {
        _verSion = value;
        OnPropertyChanged(() => verion);
    }
}

I have not done this using a message box. You can try the same. Open a window "About Us" or something. Take a string and bind it to this property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM