How to solve the error that prevents clickonce app to start - c#

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.

After so much time entangled with this error, I:
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.
adjusted namespaces and installed the needed Nuget packages and references.
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...
I'm back to the game, publishing again!
PS: I never more will let a temporary certificate expires...

Related

MSTesthacks - Running in Continous Integration using Microsoft ALM not working

I am using MSTest to run my unit test and for some reason, all the test are failing with the following error message
Unit Test Adapter threw exception:
Data source 'XXX.YYY.DriverData.aboutThemContactInformationFlows' cannot be found in the test configuration settings..
But the test are running fine in my local machine. Not sure whats going wrong.
I am having visual studio 2015 in my test machine as well in my dev machine.
The same setting is running fine in my dev machine.
Read other thread that points to missing app.config file in the test project. I do have a app.config file in the test project.
Is there any thing which I am missing. Below is the test settings file
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="UITestSettings" id="1623gdcf4-f2af-496f-b65h4-fe25w6c4e49cb" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a remote test run.</Description>
<Deployment>
<DeploymentItem filename="XXX\TestData\LocationData.xls" />
<DeploymentItem filename="XXX\TestData\UITestData.xls" />
</Deployment>
<Execution parallelTestCount="0">
<Timeouts runTimeout="36610000" testTimeout="36610000" />
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdcs9d9-ddb5-4fa4-a97d-d965ccdfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4ess7599fa-5ecb-43e9-a887-cd63cfdf72d207">
<Browser name="Internet Explorer 9.0" MaxConnections="6">
<Headers>
<Header name="User-Agent" value="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
<Properties>
<Property name="TestSettingsUIType" value="UnitTest" />
</Properties>
</TestSettings>
Well, the dev machine is a Win10 machine and the test machine is also win 10 machine.
Help pls. Any information would be much much helpful
It may or may not help you now, but I've just encountered the same problem with MSTestHacks and in my case, as in yours, I already had an app.config which is the suggested solution in various GitHub issues. I tracked it down to having made an assumption about the fully qualified namespace that you need in the DataSource attribute.
In my case I had assumed the namespace was
FrontOffice.BusinessLogicLayer.Tests.Queries.GenericTools.GetToolsForPartnerQueryTests.TestCases
This is because the project was named FrontOffice.BusinessLogicLayer.Tests. But when I checked the Assembly name and Root namespace fields in the project properties I discovered that they had been set as FrontOffice.BusinessLogicLayerTests.
Once I corrected this it ran as expected. It seems really obvious but check your namespaces carefully as unless you created them there's always a chance someone else did the (to my mind) stupid trick of having projects whose names do not match their namespaces.

Can't run c# program

my problem is i just finished a C# program using visual studio 2012 , sql server management studio 2014 , sap crystal report and .net framework 4.5.1
this is not my first program i finish using these programs by the way
then i created a setup file and copied it to another pc and tried to start it but the program don't start or even give me an error message so i tried on of my old programs on the same pc which i made in the same way it worked
so what should i do ?
by the way this pc i setup .net framework 4.5.1 on , sap crystal report runntime and the same sql server version
this is the error in the windows event log
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2016-01-18T01:22:02.000000000Z" />
<EventRecordID>6715</EventRecordID>
<Channel>Application</Channel>
<Computer>Tota-pc</Computer>
<Security />
</System>
- <EventData>
<Data>
Application: FALCON HR.exe Framework Version: v4.0.30319
- List item
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
Stack:
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(System.Data.DataSet, System.Data.DataTable[], Int32, Int32, System.String, System.Data.IDbCommand, System.Data.CommandBehavior)
at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable[], Int32, Int32, System.Data.IDbCommand, System.Data.CommandBehavior)
at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)
at FALCON_HR.DAL.DataAccessLayer.SelectData(System.String, System.Data.SqlClient.SqlParameter[])
at FALCON_HR.BL.CLS_SHAPE.get_shape_state()
at FALCON_HR.FRM_LOGIN..ctor() at FALCON_HR.Program.Main()
</Data>
</EventData>
</Event>
SOLVED: this all was about the connection, i gave the program a server name that was not exist any where but my computer .
Thank you all for your attention & your answers .

Elevate permissions for exe permanently

I have built an installer for my application with wix. I am also using an automatic updater so the user can update the software. The problem I am having is for the updater to work it needs to run its exe and close my application and restart my application after it has finished. When the updater starts up, it needs elevated permissions to run. I am wondering if there is a way to permanently grant the updater exe elevated permissions on install since it has to be installed by an administrator to begin with, saving the administrator from being present every time an update needs to be done?
It would be nice for the user to click update and not have to bother their IT department to get an updated version of our software.
Without being a member of the windows build team you only have two options
Start your program from another program that was already running that has administrator privileges
Make it so your update process does not require administrative privileges.
The only real way to perform #1 is to have a windows service that runs in the background and executes the downloaded update package as an administrative user, this process is hard to do "right" without leaving security holes in the end users system that malware (or users that want to get around IT's restrictions) could exploit.
Option #2 is the better option, and is what many popular software packages use. The way to accomplish this is to either change the permissions of your folder inside ProgramFiles to allow the Authenticated Users group to have write privileges. This is not the optimal solution but likely the easiest to implement. Another way to accomplish this is install the updateable resources in to a folder that your user has write access to by default, for example the %LocalAppData% folder (which is what Chrome does (I think) and any applications deployed with ClickOnce)
You need to add a manifest to every executable that always needs to run elevated. Here is a sample app.manifest file:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplicationName" />
<description>My application description.</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
</application>
</compatibility>
</asmv1:assembly>
The relevant setting for this in the manifest is:
level="requireAdministrator"
You just need to add an app.manifest file to your project, and then set the manifest in the Properties tab for the project to the new file instead of using the default manifest generated by the compiler.
The Windows account running the process still requires administrative privileges however for the process to run with these privileges.

Visual Studio 2010 Setup Project marks application as requiring elevation

EDIT: I would still like an answer to this question if anyone can provide one, however I have decided to split out the non-administrative part of this project into another project which will call this project as required.
I have a project which manipulates some registry keys under HKLM - which obviously requires elevation. The application knows when it needs this elevation and will re-launch itself with runas to get elevation.
In the development environment this works fine, and the application also runs fine on intended targets in this form.
When I pump the project through a VS2010 setup project and install the project on the target system, the EXE gets marked as requiring elevation and requests it whenever it gets run before the application logic determines if it needs it.
I have searched for an hour or so and found nothing which relates, though I suspect the power of my search terms is insufficiently strong (or I lack the right ones) to find an appropriate result.
How can I stop the setup project from marking the executable as requiring elevation?
Subsequent to the comment below I added a custom manifest to the project with the same result, the manifest looked right to me:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
Here's the output of the project's build (in the obj folder since that's what's being pulled in by the setup project):
http://i.stack.imgur.com/elrQh.png
The outwardly obvious thing is the lack of the UAC shield on the executable. After building the setup project, then installing it via the resultant MSI, the installed executable is like this:
http://i.stack.imgur.com/A33qz.png
Noting the now existing UAC shield.
Before adding the custom manifest, it was set to use a default one (which I suspect has the same content).

Exception: type initializer for 'system.data.sqlclient.sqlconnection'?

I couldn't figure out what is the problem for this exception.
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception
First attempt: I was using the WCF Service to make some small application. It works just fine and I can use the LINQ properly. After 2 or 3 days. Maybe after I close Visual studio and load the project again. The exception appear.
The 2nd attempt also the same. I create another project and it work just fine until I do something else (I do not change any code)
SQL Server working fine and I can connect through SQL Management Studio without problem.
A click at Debug error lead me to the connection string from linq file.
What could be the problem? I tried to search but couldn't find the answer to resolve this.
Thank you
This most likely means that there is an error in your app.config file, e.g. badly formed XML or unexpected elements. The error happens because the static fields inside SqlConnection read from app.config to determine trace detail level as described here: http://msdn.microsoft.com/en-us/library/ms254503.aspx
If you have a project that contains the NuGet packages for both Oracle and SQL Server, this solution might help you fix this error.
Uninstall both of these NuGet packages:
Oracle.ManagedDataAccess.Core
System.Data.SqlClient
Open your app.config and check if you still have have any dependent assembly entries listed. If you do, delete those entries now. They might look something like this:
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.19.1" newVersion="2.0.19.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlClient" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.1" newVersion="4.5.0.1" />
</dependentAssembly>
While still in your app.config file, delete the entire Oracle Managed Data Access section if it exists (This might be the only thing that you need to do to fix this problem, however we performed all of the steps listed in this solution). If you have it, it might look something like this:
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<!-- your TNS_ADMIN value would be located here -->
</settings>
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
</dataSources>
</version>
</oracle.manageddataaccess.client>
Open the packages.config file and double check to ensure that the entries for the Oracle and SQL Server packages are not still listed - they should be gone, but it doesn't hurt to be 100% sure.
Save your project, and then re-add the NuGet packages.
Delete app.config and then run the program
I also faced that exception once when I reopened my project. In my case the Config file had empty tag and key as you can see below. I removed the appSettings tag to fix the problem.
< ?xml version="1.0" encoding="utf-8" ?>
< configuration>
< appSettings>
< add key="" value="site"/>
< /appSettings>
< configSections>
< /configSections>
< /configuration>
Check if you have the following Windows hotfix installed - KB2840628 - for the .NET FW 4.0 (use Windows Control Panel->Programs+Features and click 'view installed updates') and if so try uninstalling it...
https://connect.microsoft.com/VisualStudio/feedback/details/793500/sqlclr-typeinitializationexception-in-sqlconnection-since-kb2840628
It resolved the problem for me.
In my case , the problem was modifying tag name in app.config file by mistake
just compare your app.config file with another old one .. You will find out the problem
...
I have the same error. And I findout the solution for it by change "app.config":
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="O4E.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<applicationSettings>
<O4E.Settings>
<setting name="abc" serializeAs="String">
<value>xyz</value>
</setting>
</O4E.Settings>
</applicationSettings>
<appSettings>
<add key="" value=""/>
<add key="" value=""/>
</appSettings>
</configuration>
Note:
Line [supportedRuntime version="v2.0.50727"] is the most importance.
I've read a lot about this issue, but no one has mentioned the following cause of this error.
Some of our users, who had an older version of VMWare View Client which was then upgraded, are now seeing this issue.
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception
Users who only had just the old version of VMWare View Client installed have no problem.
Users who only had just the new version of VMWare View Client installed have no problem.
But users who had an old version of VMWare View Client, but have now been upgraded, do have a problem, and it does continue even if we uninstall VMWare View Client, then install the new version.
We did attempt to reinstall .Net Framework and Visual Studio Tools for Office, but this didn't fix anything.
We haven't found a fix yet, but I hope this helps other users.
Btw, we did check our app.config's and web.config's, and these are all fine (and work perfectly with the rest of our users).
One other discovery:
If your user has local admin rights, this problem doesn't occur after upgrading VMWare View Client.
If they don't have local admin rights, the issue will occur.
So... we're now stuck.
I have a test laptop, and I can reproduce the error everytime when my user ID doesn't have Local Admin rights. If we then grant Local Admin rights, and I log in again, the error goes away.
And I added a load of try..catch's in my code, and found that the exception occurs in this one line of code:
MikesDataContext dc = new MikesDataContext()
So, it's actually making the connection which throws the exception. It does not get as far as the next lines of code which use this connection.
sorry for the late response on this, but after investigating this issue for almost 3 days in a row I thought I'd share my results.
I had the same error pop up in SQL Server Reporting Services, more specifically the web portal after getting HTTP 503 Service Unavailable errors on my browsers.
Turns out that the issue was related to both, the service account that runs the SSRS instance plus the account that connects to the database, which in my case was located on another server than the reporting instance. I haven't yet been able to pinpoint exactly where the problem lies inside the configuration and/or user rights, i.e. where do the accounts exactly need elevated rights. All in all seems that the underlying problem was that the account I was running the web portal code under, didn't have enough rights to call on the System.Data.SQLClient type.
TL;DR: Check your users permissions! Hope this helps someone, I had a long 3 days trying to figure this out.
A similar solution to those mentioned above, but in my case it was the
applicationSettings tag within the app.config that needed to be removed.
I have the same error and the problem was in Web.config.
In my case, just add the connectionStrings tag and its value and problem solved.
<connectionStrings>
your connection strings
</connectionStrings>
I have run across this issue on programs that work fine for months, but sudden stop working.
The fix I have found works every time is to place this as the first call in your Main().
System.Configuration.ConfigurationManager.GetSection("system.xml/xmlReader");

Categories