【发布时间】:2019-12-25 03:51:33
【问题描述】:
我有一个应用程序配置为在控制台上运行或作为服务运行(取决于我是手动运行 .exe 还是安装它)。
从命令行运行它效果很好......但是当我将它作为服务安装时,我收到一个文件加载错误:
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.
需要这个包,因为我使用 EntityFrameworkCore 和 Pomelo 库来查询 MySQL 数据库。我已确保包含所有必需的 NuGet 包并且是最新的。
我已经做了一些事情来纠正这个错误,老实说,我看不出我错过了什么......
首先,我的程序一开始就运行这一行,以确保服务从我期望的目录(而不是 system32)运行:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
接下来,我尝试将特定包恢复为 v2.0.0.0 以匹配错误描述...不过,一旦我使用恢复的包构建它,其他包就会抛出错误,他们正在寻找更新的版本 v2 .2.6.0
我还尝试删除生产机器上对 v2.0.0.0 的所有引用...所以它甚至不会寻找那个
我的 .csproj 文件只引用了最新版本:
<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>
我什至在我的 app.config 文件中有一个绑定重定向,似乎完全被忽略了:
<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>
现在我对我可能丢失的内容感到非常茫然...如上所述,我只在作为服务运行时收到文件丢失错误...
为什么我的应用程序在作为服务运行时找不到正确的程序集版本?我该如何解决这个问题?
【问题讨论】:
-
它可能正在尝试从 GAC 加载程序集。您可以尝试在完全控制台模式下运行它,而不是在 Visual Studio 中。
标签: c# mysql windows-services entity-framework-core .net-assembly