c# - assembly file load error when running application as windows service
问题描述
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=2.2.0.0' ... 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):
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
Next, I tried reverting the specific package to v2.0.0.0 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 v2.2.6.0
I have also tried removing all references on the production machine to v2.0.0.0... so it wouldn't even be looking for that
My .csproj file only references the latest version:
<Reference Include="Microsoft.EntityFrameworkCore.Relational, Version=2.2.6.0, 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-2.2.6.0" newVersion="2.2.6.0" />
</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?
解决方案
推荐阅读
- postgresql - 如何将 postgresql 与 graphql 连接起来
- python - 如何使用openpyxl在正常模式下保存excel工作簿?
- java - 从 SVN 中删除文档时出现问题
- c++ - CMake 为 boost 标头选择了错误的库
- sql - sql server 对执行计划不采取最严格的条件
- layout - 如何将 pageView 添加到我的颤振 main.dart 代码中?
- java - Oreo - 闪烁通知 LED
- html - 引导轮播中心图像垂直和水平
- python - 通过 Drive API 在国际设置中创建具有设置区域设置的 Drive 文件
- kotlin - 如何在 Kotlin 中获取对象的地址?