'How to solve the error that prevents clickonce app to start

BACKGROUND:

I'm having a problem with a ClickOnce WindowsForms NET 4.8 App that now is composed of a Solution with 2 projects. All began after auto generated certificate expired after 2 y. I do not know if it is relevant, but at the beginning it was only one project that I split in two and used the same generated key for both.

So, I generated new on signing Tab, with Create Test Certificate (wish I had known about extend life of old one... but now it is deleted) and, because they are two projects, with 2 Apps (but I'm using Model and Services from the other) I generated one Test Certificate for each.

At Signing Tab the option sign the ClickOnce manifests is checked, but not the Sign the assembly (neither before were).

I can build, run, debug and use it normally; but, if try to Publish to the same place as before I receive the msg:

The application is signed with a different key than the existing application on the server. Do you want to overwrite it?

As it is a development phase still, I do not care about it and overwrote it.

CURRENT PROBLEM:

App is Published, but it not starts, and gives no clue or msg.

At the Program.cs I have, of course:

        Static async Task Main()
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += ApplicationOnThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
       //...
       }

How I tried to investigate:

So, I changed my Output folder and of course there is no more ... application is signed with a different key than ... but the App still doesn't starts and gives no msg. Same behavior in two other Windows 10 PCs. I'm using VS 2022 64 bits and Windows 10, both fully updated as always.

After I saw this I changed to Create application without a manifest to no avail.

I went to the event viewer console and there is two error msgs, at same TimeStamp:

The first one is:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name=".NET Runtime" /> 
  <EventID Qualifiers="0">1026</EventID> 
  <Version>0</Version> 
  <Level>2</Level> 
  <Task>0</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2022-03-18T14:52:57.3515638Z" /> 
  <EventRecordID>226871</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="0" ThreadID="0" /> 
  <Channel>Application</Channel> 
  <Computer>Computer-NAME</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>Application: applaunch.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Information: exception code e0434352, exception address 00007FFA01334F69 Stack:</Data> 
  </EventData>
  </Event>

The second one:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Error" /> 
  <EventID Qualifiers="0">1000</EventID> 
  <Version>0</Version> 
  <Level>2</Level> 
  <Task>100</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2022-03-18T14:52:57.5775648Z" /> 
  <EventRecordID>226872</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="0" ThreadID="0" /> 
  <Channel>Application</Channel> 
  <Computer>Computer-NAME</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>applaunch.exe</Data> 
  <Data>4.8.4084.0</Data> 
  <Data>5dda4211</Data> 
  <Data>KERNELBASE.dll</Data> 
  <Data>10.0.19041.1566</Data> 
  <Data>0833f2d4</Data> 
  <Data>e0434352</Data> 
  <Data>0000000000034f69</Data> 
  <Data>13368</Data> 
  <Data>01d83ad7dade31c5</Data> 
  <Data>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\applaunch.exe</Data> 
  <Data>C:\WINDOWS\System32\KERNELBASE.dll</Data> 
  <Data>507e79be-c718-4d23-bab8-f153b4601c3b</Data> 
  <Data /> 
  <Data /> 
  </EventData>
  </Event>

Lastly, I unchecked the Sign the ClickOnce manifests; the behavior remains the same and the vanilla error msgs at Event Viewer too.

If I understand correctly, because of none my global error handlers catch it, I'm assuming that the error is firing before any of my code is even loaded in memory and it is related to the certificate changing, but I'm not sure. I'm lost in how to further investigate it. Any directions?

TIA

EDIT 1: To further investigate I enabled the verbose installation.log as per these instructions. To my surprise both the functioning version (published with the non-expired key) and the new one (with the new key) output the same installation.log. With this weary information I went to Published folders (%AppData%\Local\Apps\2.0...) and to my further surprise I could instantiate not only the Operational App - with a different behavior regarding displayed version number - but could initiate the missing new version App from its Published folder.

And yes, I correct filled Publisher name and Product name.



Solution 1:[1]

After so much time entangled with this error, I:

  1. followed the advise of this thread and I created entirely different solution/projects, from scratch, and I copied all my files (.cs, forms, assets...) to the new one.

  2. adjusted namespaces and installed the needed Nuget packages and references.

  3. signed the ClickOnce manifests with the Create Test Certificate as usual, but few minutes after I changed the duration of .pfk key to several years; it must be done BEFORE it ever expires, and I'll forget for sure; so, did it in sequence because, if after, no effect at all...

  4. I'm back to the game, publishing again!

PS: I never more will let a temporary certificate expires...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1