1

I'm having this exception when trying to use any of the Deployment members like for example I try in this simple code:

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    MsgBox(If(My.Application.Deployment.IsFirstRun, "Yes", "No"))

End Sub

End Class

Exception message: Application identity is not set

The exception occurs in debugging and also in release, in VS2012, targeting FW 4.0 in a Winforms.

I've read here: Application identity not set Exception

...And also here: InvalidDeploymentException - Application identity is not set

I don't remember how to deactivate the exception checking in the project settings but anyways there is a way to avoid this exception without manually disabling exceptions?

The reason is just I don't want to manually disable exceptions and remember to do it for each of my stored and future projects, I want to fix this problem in a natural way.

Community
  • 1
  • 1
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

2 Answers2

5

Is it a ClickOnce application? It is network deployed? Are you debugging? That would not work in debug mode.

If you are debugging, use this to test:

If Not System.Diagnostics.Debugger.IsAttached Then
    firstRun = My.Application.Deployment.IsFirstRun
End If

-

As it is not a network deployed application, I would check if the application has been previously launched saving a user settings or establishing a value in the registry.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
  • thanks but Does not worked, it occurs when debugging and also when not, running the executable from IDE and running compiled exe from release folder. – ElektroStudios Oct 17 '13 at 13:52
  • it's a simple WinForm, just the form has the code that I've posted, anymore. – ElektroStudios Oct 17 '13 at 13:56
  • Ok, it is a winform, but are you deploying the application using IIS as a clickOnce app? – Carlos Landeras Oct 17 '13 at 13:58
  • Try using Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun, instead of My.Application.Deployment.IsFirstRun. Same result? – Carlos Landeras Oct 17 '13 at 13:59
  • I got the same exception – ElektroStudios Oct 17 '13 at 14:02
  • Could you paste a StackTrace? – Carlos Landeras Oct 17 '13 at 14:07
  • en System.Deployment.Application.ApplicationDeployment.get_CurrentDeployment() en WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e) en C:\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Form1.vb:línea 8 – ElektroStudios Oct 17 '13 at 14:17
  • the line makes refference to the 'Deployment.IsFirstRun' instruction. – ElektroStudios Oct 17 '13 at 14:17
  • do you know if I delete my question if the points I gived you will be deleted also with my question? if points will be preserved to you then I just delete my question 'cause really does not has sense. – ElektroStudios Oct 17 '13 at 14:33
  • @ElektroStudios You won't be able to delete the question now; there are several reasons and they are given in [How does deleting work? What can cause a post to be deleted, and what does that actually mean? What are the criteria for deletion?](https://meta.stackexchange.com/q/5221/232762) – Andrew Morton Jul 26 '19 at 10:36
1

The method that you are calling is only available with a click-once deployed application. You must surround all deployment code in an IF like this:

If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
...Your code here
End If

Or else it will error.

This does make it hard to debug your code, because it will only run when deployed, but you should create a test application with message boxes to see what is happening.

If you are not creating a click-once deployment, dont use these classes!

Steve
  • 5,585
  • 2
  • 18
  • 32
  • 1
    He answered me it is not network deployed. It is just a form. I copy from him: it's a simple WinForm, just the form has the code that I've posted, anymore. " So I discarded your answer – Carlos Landeras Oct 17 '13 at 14:19
  • Thanks @Steve, just I've read that the method will help us to know if it is first time run of the application, but nothing said about it just only works for deployed applications, there is any equivalent to know if IsFirstRun of an "normal" application?, I know how to do this using a lot of code writting a registry key with a boolean flag, but I just wondered that can be simplified in one line. – ElektroStudios Oct 17 '13 at 14:20
  • @Electro Hacker, Then it will never work if not networkdeployed.That's why I asked!. Use a user setting or a registry key to manage if application was launched before!. – Carlos Landeras Oct 17 '13 at 14:22
  • Understanded @Carlos Landeras, is my fault for been confussed about the usage of that class methods, I've just supposed that the method worked for all kind of applications – ElektroStudios Oct 17 '13 at 14:23
  • Registry Key is what you want, and it is not a lot of code. Look at [GetSettings](http://msdn.microsoft.com/en-us/library/kb0c3wb9(v=vs.90).aspx) [SaveSetting](http://msdn.microsoft.com/en-us/library/3kz7fyks(v=vs.90).aspx) – Steve Oct 17 '13 at 14:27
  • then I know how to, just I wanted to simplify it, thanks again – ElektroStudios Oct 17 '13 at 14:27
  • @Steve do you know if I delete my question if the points I gived you will be deleted alsowith the question? if points will be preserved to you then I just delete my question 'cause really does not has sense. – ElektroStudios Oct 17 '13 at 14:33
  • I dont know, but you should leave it. It will be helpful to others that might have the same misunderstanding. – Steve Oct 17 '13 at 14:35
  • 1
    @ElektroHacker do not remove it. Maybe another persona finds the isFirstRun and try to use without knowing is for NetworkDeployed apps. It might be useful – Carlos Landeras Oct 17 '13 at 14:38