ClickOnce: Application identity is not set.

I am trying to create a simple ClickOnce program that checks for updates programmatically. I have succesfully published a program using the built in functionallity of the IDE, but this does not give me what I want.

Firstly, how do you debug such a program, as when I run the program, it falls over when I try to get theCurrentDeployment object with an error: The application is not installed.

Secondly, I created a setup project and installed my program, but I am now getting the error: Application identity is not set. I'm sure this is just a property that needs setting somewhere, but I cannot find it.

Here is my code:

PrivateSub Form1_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load

Dim objAppDeployAs System.Deployment.Application.ApplicationDeployment

objAppDeploy = System.Deployment.Application.ApplicationDeployment.CurrentDeployment

If objAppDeploy.CheckForUpdateThen

EndIf

EndSub

And here is the full error when trying to run the installed apllication:

************** Exception Text **************
System.Deployment.Application.InvalidDeploymentException: Application identity is not set.
at System.Deployment.Application.ApplicationDeployment.get_CurrentDeployment()
at System.Deployment.Application.ApplicationDeployment.get_CurrentDeployment()
at ClickOnce.Form1.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50215/mscorlib.dll
-
ClickOnce
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase:file:///C:/Program%20Files/IMS/ClickOnceSetup/ClickOnce.exe
-
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
-
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
-
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
-
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
-
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
-
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
-
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
-
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
-
System.Deployment
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
-
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
-
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
-

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

[9914 byte] By [IMS] at [2008-2-17]
# 1

Hi,

The deployment APIs will throw an exception when the application was not deployed via ClickOnce. So, whenever you use those APIs, you should first check whether the application has been ClickOnce deployed as follows:

If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
' Do deployment logic
End If

It sounds like you are deploying the app using the setup projects (which use MSI) rather than ClickOnce. Although it's possible (and a bit complicated) to use these technologies together, typically you choose between one or the other. In your case, the exception is basically telling you that the app was not deployed by ClickOnce so it has no application identity.

Instead of using a setup project, just right-click on your application's project and select the Publish command. This will launch a wizard that will deploy the application using ClickOnce.

Hope this helps,
Sean: VBPM

SeanDr_MS at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 2

I wrote a tiny app that copies itself to C:\Windows\system32 (or the system special folder), because I want to run it from a scheduled task. (It's a SOAP service client for uploading sales files.)

Is there a way to specify the install path, so I don't have to do that? Or should I just use a setup project instead of ClickOnce?

AaronWest at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 3

Hi!

I had the same problem, same exception.

But When I've added the check you suggested It results "not network deployed"!!!

But I deployed using the menù "Build" and "Publish" like you said.

Any other suggestions?

Thx!

fedrok at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 4
You have to actually be running a deployed version to get the code to work... It doesn't run under the debugger.

This may make debugging difficult and annoy users because you have to deploy new version to test code. I suggest making a test project to implement and test all deployment code before presenting it to users.

Jacob Christ

JacobChrist at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic IDE...