I have developed a Winforms C# app (.NET Framework 4.8), which used to run fine. Last change, I decided to add a Map control using Gmap.NET. At first everything looked fine, in debug, so gave it a go, and built a release version (IMPORTANT NOTE: my solution has 2 Projects - the first contains the Winform app, and the second is a Setup Project created with the Microsoft Visual Studio Installer Projects 2022 extension).
From that starting point:
- The Release build was succesful. Installed the new version --> crashes on start (splash screen briefly shows, and then disappears. Main form does not load)
- I did some research, and it looks like GMap.net has some issues, and I had to manually edit the .csproj file to get all dependencies right (explained in this question) 3.Apparently some other reference was wrong, as it was still not working. I cleaned up Nuget packages for the solution, as well as referenced dlls
Current status:
- No exception thrown. Program runs fine on debug mode
- Program runs fine if I click on the .exe in bin/debug or bin/release of the Winform project
- Program hangs on start f I copy the whole bin/debug or bin/release to other location and start from there
- Program crashes on start if I install it and launch normally
I am at a loss here. I have tried Assembly Log Binding Viewer but only some messages about XML.Serialzers there and, according to this question it is fine to ignore them. I have tried debugging without the "Just my code" option, but I do not see anything there. I have also populated my code with writes to a log file and I can see there that:
When launched from a copy of the bin (debug or release)folder elsewhere, the program writes the log as if it was completely initialized, but the main form is hung and does not show the controls
When launched from the bin (debug or release) folder, runs as intended
When launched from the instalation path it crashes immediately and the log shows traces up to the call to InitializeComponent() :
public Form1()
{
using (StreamWriter sw = File.AppendText(Application.UserAppDataPath + @"\mainlog.txt"))
{
sw.WriteLine("Initializing Form 1 components");
}
InitializeComponent();
using (StreamWriter sw = File.AppendText(Application.UserAppDataPath + @"\mainlog.txt"))
{
sw.WriteLine("Form 1 components initialized");
}
to be precise, last message in the log file is "Initializing Form 1 components" but, if I try to debug step by step inside InitializeComponent() I see no exception, and it works (as always in DEbug mode from Visual Studio)
I am suspecting that some of my code is referencing a DLL and, when it is run outside the bin folder, it cannot find it. It should be included by the installer, though, and I am not able to find any exception (tried placing some try-catch blocks around to no avail) or message giving me a hint. So I am open to test any options... just be kind and constructive, as I am a HW guy out of his comfort zone, and some of my code might be a mess. I can paste specific code blocks per request, but the whole app is now sitting at roughly 30K lines, so we better be specific (also that is the reason I don not throw this into the bin and start all over).
EDIT1: after @Deolus comment, I looked again in the Event Viewer and I see this:
Application: DatacardGenerator.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.DllNotFoundException
at System.Data.SQLite.UnsafeNativeMethods.sqlite3_libversion()
at GMap.NET.CacheProviders.SQLitePureImageCache.Ping()
at GMap.NET.WindowsForms.GMapControl..cctor()
Exception Info: System.TypeInitializationException
at GMap.NET.WindowsForms.GMapControl..ctor()
at WindowsFormsApp2.Form1.InitializeComponent()
at WindowsFormsApp2.Form1..ctor()
at WindowsFormsApp2.MyApp.OnCreateMainForm()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(System.String[])
at WindowsFormsApp2.Program.Main(System.String[])
Faulting application name: DatacardGenerator.exe, version: 1.7.1.0, time stamp: 0x9971e3f6
Faulting module name: KERNELBASE.dll, version: 10.0.19041.2546, time stamp: 0xe8e9ac9b
Exception code: 0xe0434352
Fault offset: 0x000000000002cd29
Faulting process id: 0x844
Faulting application start time: 0x01d951b04b7a219a
Faulting application path: C:\Program Files (x86)\GV5Js\GV5JsDatacardGenerator\DatacardGenerator.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 2d3c200b-e6e6-4be2-bbd3-9efd45f05bfe
Faulting package full name:
Faulting package-relative application ID: