ServiceStack:测试OrmLite,已安装NuGet但出现“FileNotFoundException”错误

3
我刚刚在Visual Studio 2012中通过NuGet安装了OrmLite(适用于MySql)。安装过程无误,并且所有DLL似乎都已被添加为引用:ServiceStack.Common(3.9.70.0)、ServiceStack.Interfaces(1.0.0.0)、ServiceStack.Text(3.9.70.0)、ServiceStack.OrmLite(3.9.70.0)和ServiceStack.OrmLite.MySql(3.9.70.0)。编译没有错误。但是,当我运行以下代码时:
dbConnCommOrm.CreateTableIfNotExists<ModuleSettings>();

然后我收到了以下错误信息:
无法加载文件或程序集“ServiceStack.Common,Version=3.9.69.0,Culture=neutral,PublicKeyToken=null”或其其中一个依赖项。系统找不到指定的文件。
通过NuGet引用的ServiceStack.Common dll版本为3.9.70.0,因此它无法找到3.9.69.0并不奇怪。
问题是:为什么我安装需要3.9.69.0而却安装了3.9.70.0?是NuGet“脚本”(或者它是如何工作的)出了问题,还是我漏掉了什么?
奇怪的是,即使我在上述行中收到异常,表“ModuleSettings”仍然被正确创建!
此外,从GitHub下载ZIP文件并从中提取DLL也不起作用: 在 ServiceStack.OrmLite-master\lib 中有前三个文件(见上文),出于某种原因,我在 ServiceStack.OrmLite-master\lib/signed 文件夹中发现了 ServiceStack.Ormlite.dll,但在 ZIP-file 中没有找到 ServiceStack.OrmLite.MySql.dll
我还要补充一点,安装旧版本也不起作用。我尝试过这样做: http://www.nuget.org/packages/ServiceStack.OrmLite.MySql/3.9.69

PM> Install-Package ServiceStack.OrmLite.MySql -Version 3.9.69

但它仍然安装了 ServerStack.Common/Text v 3.9.70.0。
任何提示将不胜感激 =)
2个回答

4
你是否尝试在你的web.config文件中添加程序集重定向?
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="ServiceStack.Common" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.9.70.0" newVersion="3.9.70.0" />
      </dependentAssembly>
   </assemblyBinding>
</runtime>

可能是你安装的某个软件包中的一个项目正在专门寻找3.9.69.0版本,但尚未更新。使用程序集绑定重定向应该可以覆盖它,并将所有对该程序集的请求重定向到3.9.70版本。
编辑:
这对非Web项目也起作用。打开(或添加)app.config文件,并添加相同的信息。它是元素内的顶级元素。
如果是空的app.config文件:
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="ServiceStack.Common" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.9.70.0" newVersion="3.9.70.0" />
          </dependentAssembly>
       </assemblyBinding>
    </runtime>
</configuration>

谢谢!但这不是一个Web项目...这是一个dll项目,所以我没有web.config。那么我应该把这样的重定向放在哪里呢? - Ted
你可以在 app.config 文件中使用相同的功能。如果没有该文件,只需右键单击项目,添加配置文件即可。 - Tommy
谢谢,我刚刚发现在app.config中添加了这样的绑定重定向,但是针对的是MySql.Data。我刚刚添加了你的代码片段,它有效了=)非常感谢您的快速回答,非常感激。 - Ted
你认为这是ServerStack端的一个bug吗?因为我们不应该需要做这个解决方法,对吧? - Ted
1
我知道微软产品更新中的许多(MVC、EntityFramework等)会自动从NuGet添加这些重定向。我不会称其为“错误”,只是您刚刚安装了6个程序集,其中一个在引用正确的程序集版本时未被创建者更新。因此,这种“解决方法”帮助更新项目中的一个.dll,以避免其他具有特定版本依赖关系的文件出现问题。 - Tommy
显示剩余3条评论

-1
在我的解决方案中,我有以下项目:Site、BusinessLogic、DAL。
调用链为:Site -> BusinessLogic -> DAL(这里使用OrmLite)。
由于ServiceStack的松耦合性,Site项目没有引用ServiceStack.Common。我的解决方案是:
安装-Package ServiceStack.Common -Version 3.9.71 -DependencyVersion Highest
对于Site项目。请注意使用DependencyVersion,否则您将获得较低版本的ServiceStack.Text,事情会变得不愉快。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接