0

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:

  1. The Release build was succesful. Installed the new version --> crashes on start (splash screen briefly shows, and then disappears. Main form does not load)
  2. 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: 
  • do you run the setup if outside the bin folder or do you run the executable directly? – Aaron Mar 08 '23 at 10:42
  • Do you get any application errors in the Windows event viewer? – Deolus Mar 08 '23 at 10:45
  • @Aaron : I run the executable directly – Francisco Benito Mar 08 '23 at 11:21
  • @Deolus you might be on the right track. I had been looking there and I just saw an event when I force closed the hung form. But right now I have looked and I see this: (see EDIT1) – Francisco Benito Mar 08 '23 at 11:23
  • 2
    I'm no expert at solving problems like this but I'm guessing the app needs sqlite3.dll. If you can see that .dll on your project try setting the properties to copy it to the application folder. – Deolus Mar 08 '23 at 12:32
  • Thanks, I am following that route: first I had to manually download SQLite files, as for some reason the Nuget package is not working, and the folder at packages contains no DLL. Then I got a BadImage exception, which means the version of SQLite.Interop.dll is wrong (x86/x64), so I made sure I was compiling both projects with a target of x64 and that the dll is the right one. Right after that, the exception thrown is System.EntryPointNotFoundException at System.Data.SQLite.UnsafeNativeMethods.sqlite3_libversion() and this is what I am investigating next – Francisco Benito Mar 08 '23 at 12:41
  • Maybe this [SO question](https://stackoverflow.com/questions/57804978/c-sharp-clickonce-publishing-dll-issues-with-gmap) could help. – mehdi.loa Mar 08 '23 at 13:39
  • Hi, if possible, could you please share the designer part of the Form(code which can reproduce this issue.)? – Bowman Zhu-MSFT Mar 09 '23 at 06:59

1 Answers1

1

Ok, it finally works.

It all boils down to not having the right version of SQLite.Interop.dll. As my "\packages\System.Data.SQLite.Core.1.0.117.0" and "\packages\System.Data.SQLite.1.0.117.0" folders only showed a .p7s and .nupkg file, and now dlls at all, I had downloaded the dlls, and it seems they were wrong. Making a search for SQLite.Interop.dll in my ackages folder found the right ones under "\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net46\x64" and "\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net46\x86".

Adding those files, as explained here did the trick :)