c# - 无法从 OrmLiteConfigExtensions (ServiceStack.OrmLite.Core) 加载 System.ComponentModel.Annotations
问题描述
使用ServiceStack.OrmLite.Core
包 (5.4.1) 并尝试通过执行以下操作获取ModelDefinition
( ServiceStack.OrmLite.ModelDefinition
) 时出现运行时错误:
var model = ModelDefinition<T>.Definition;
错误如下:
System.IO.FileLoadException: 'Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
我试图安装 nuget System.ComponentModel.Annotations (4.5.0.0,因为 4.2.0.0 不可用)无济于事。我还尝试了遇到 System.IO.FileLoadException 时建议的各种修复,但没有任何效果。
该项目是一个 .Net Framework 4.7.1 项目,但 .Net 标准项目包含在解决方案中,因此我需要运行 ServiceStack.OrmLite 的 .Core 版本。
我已经在两个工作区(两台独立的机器)上尝试过这个,(1)如上所述,以及(2)解决方案中没有.Net Standard项目。在 (2) 机器上,它在运行 的非核心版本时可以工作ServiceStack.OrmLite
,但会发生切换到ServiceStack.OrmLite.Core
运行时错误。
有没有人有任何想法?
解决方案
终于明白了……</p>
事实证明ServiceStack.OrmLite.MySql.Core
需要System.ComponentModel.Annotations
版本 4.2.0.0,因为错误消息明确指出。通常它可以安装等于或大于所需版本的版本,但在这种情况下,这些都不起作用。并且由于某种原因,FX 中包含的最新版本似乎是 4.0.0.0(或者至少这是我在包含它的程序集版本时得到的。)还有一个 nuget 安装版本 4.5.0.0,但结果是相同。
我不知道为什么它使用 FX 版本开箱即用ServiceStack.OrmLite.MySql
,但是当我使用 Core 版本时,如果没有以下修复,我无法避免这种情况:
在我的启动项目中,我需要添加一个程序集绑定,告诉ServiceStack.OrmLite.MySql.Core
版本System.ComponentModel.Annotations
4.2.0.0 “重定向”到 4.0.0.0(同一个程序集)。它看起来像这样:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
我敢肯定有人可以解释这方面的细节,我不是其中之一,但尽管如此……将其添加到启动项目 app.config 将起到作用。
推荐阅读
- django - 如何更新包含多个表单的表单集
- java - 如何在ubuntu中完全卸载tomcat(包括服务器连接)?
- sqlite - Sqlite 邻近搜索
- c# - 输入日期选择器 - 阻止所有月份的日期
- python - 如何使用 cypher 获得一些大于 neo4j 平均值的值?
- python - 将自定义用户数据添加到 matplotlib 艺术家
- powershell - 调用 cmdlet 时省略空参数
- python - matplotlib 在两组 x,y 点之间填充关于哪一组在顶部
- python-3.x - 如何为jointplot中的色标制作归一化因子?
- kubernetes - 不了解如何最好地使用 istio 网关