I have an application configured to run on the console or as a service (depending on if I run the .exe manually or install it).
Running it from the command line works great... but when I install it as a service I get a file load error:
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Relational, Version=22.214.171.124' ... the located assembly's manifest definition does not match the assembly reference.
This package is needed because I am using EntityFrameworkCore and Pomelo libraries in order to query a MySQL database. I have made sure all required NuGet packages are included and up-to-date.
I've done a few things to remedy this error, and honestly can't see what I'm missing...
First, my program runs this line at the very beginning to ensure the service is running from the directory I expect (instead of system32):
Next, I tried reverting the specific package to v126.96.36.199 to match the error description... once I build it with the reverted package though, the other packages throw an error that they are looking for the updated version v188.8.131.52
I have also tried removing all references on the production machine to v184.108.40.206... so it wouldn't even be looking for that
My .csproj file only references the latest version:
<Reference Include="Microsoft.EntityFrameworkCore.Relational, Version=220.127.116.11, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> <HintPath>packages\Microsoft.EntityFrameworkCore.Relational.2.2.6\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll</HintPath> </Reference>
I even have a binding redirect in my app.config file that is seemingly being ignored entirely:
<dependentAssembly> <assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly>
Now I am at a real loss as to what I could be missing... As noted above, I only get the file missing error when running as a service...
Why would my application not be finding the proper assembly version when run as a service? How do I resolve the issue?
I'm honestly still not entirely sure why this happens, but I found a solution...
As far as I can tell the problem really has to do with NuGet packages not being descriptive enough.
Basically, what was happening was the package I was using stated it could use any version of
Microsoft.EntityFrameworkCore.Relational as long as it was 126.96.36.199 or greater. NuGet suggested updating to the latest version, so I did... which happened to be 188.8.131.52. This update broke it...
So reverting to 184.108.40.206 AND removing the binding redirect fixed my problem. Both of these things had to be done since only reverting to the earlier version didn't resolve that the binding redirect was forcing it to look for a later version...
Have you tried running the service/application in a "normal" account? Try entering the account where you can log in interactively and run the application onto the service's Logon tab:
(Run "whoami" at a command prompt to find your account name.)