Francisco Benito
Francisco Benito

Reputation: 23

Winforms app runs fine from bin/debug or bin/release, but not outside

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:

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:

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: 

Upvotes: 0

Views: 547

Answers (1)

Francisco Benito
Francisco Benito

Reputation: 23

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 :)

Upvotes: 1

Related Questions