新的嵌入式Firebird,代码第一,EF6项目结果在SerializationException [英] New embedded Firebird, code first, EF6 project results in SerializationException

查看:233
本文介绍了新的嵌入式Firebird,代码第一,EF6项目结果在SerializationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EF6设置Firebird作为嵌入式服务器,用于我正在撰写的简单应用程序,但无法使其正常工作。我有一个CLI项目是应用程序,DAL项目是DB。我将NuGet包添加到两个并创建了一个具有简单实体的DbContext,并且成功创建了初始迁移,但是当尝试运行 update-database 来执行我收到的迁移包管理器控制台中的此错误:

I'm trying to set up Firebird with EF6 as an embedded server for a simple app I'm writing but haven't been able to get it to work. I have a CLI project which is the app and the DAL project which is the DB. I added the NuGet packages to both and created a DbContext with a simple entity, and created an initial migration successfully, but when trying to run update-database to execute the migration I received this error in the Package Manager Console:

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'FirebirdSql.Data.FirebirdClient.FbException,FirebirdSql.Data.FirebirdClient, Version=4.10.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c'.
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'FirebirdSql.Data.FirebirdClient.FbException,FirebirdSql.Data.FirebirdClient, Version=4.10.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c'.

其实我只是注意到现在没有任何工作...如果我删除我的迁移并尝试重新创建它,我收到这个错误。我能够启用迁移,然后创建一个,但现在我不能。奇怪的是,

Actually I just noticed that nothing works now... If I remove my migration and try to recreate it, I get this error. I was able to enable migrations and create one before, but now I can't. Bizarre.

我的所有项目都是针对.NET 4.5.2,它们都有相同的软件包版本。我的解决方案/项目路径中没有空格或符号或奇怪的字符。我试过使用我的应用程序项目作为启动项目和DAL项目,并没有什么不同。

All of my projects are targeting .NET 4.5.2 and they all have the same package versions. My solution/project path has no spaces or ampersands or weird characters in it. I've tried using my app project as the startup project and the DAL project and that didn't make a difference.

我的 packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net452" />
  <package id="EntityFramework.Firebird" version="4.10.0.0" targetFramework="net452" />
  <package id="FirebirdSql.Data.FirebirdClient" version="4.10.0.0" targetFramework="net452" />
</packages>

我的 App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="DAL.DbContext" providerName="FirebirdSql.Data.FirebirdClient" connectionString="User=SYSDBA;Password=masterkey;Database=SampleDatabase.fdb;DataSource=localhost;Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=1;" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
    <providers>
      <!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
      <provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant="FirebirdSql.Data.FirebirdClient" />
      <add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
    </DbProviderFactories>
  </system.data>
</configuration>

我刚刚在网上找到的连接字符串可能是错误的,但我找不到任何文档...

The connection string I just found on the net so that might be wrong, but I couldn't find any documentation for it...

我已经用SqlServer完成了代码优先的几十次,之前从未遇到过这个问题,但是这个程序不会有一个真正的服务器打。不幸的是,这似乎是一个比Firebird或EF更为普遍的问题,但我不确定哪里甚至可以看这一点。

I've done code-first EF dozens of times with SqlServer before and never ran into this problem before, but this app won't have a real server to hit. Unfortunately this seems like a more general problem than Firebird or EF, but I'm not sure where to even look at this point.

推荐答案

p>我有这个同样的确切问题,能够准确地确定上一个答案的帮助。这是一个已知的bug,他们有一个6.2的修复。例外是隐藏更深层次的问题,如果没有适当的堆栈跟踪,可能难以知道。解决办法是将您的实体框架升级到最新的6.2预发行版本,并查看真正的问题是什么,然后恢复到您当前的版本,在我的情况下是6.1.3

I had this same exact issue and was able to figure out exactly what was going on with the help of the previous answer. It is a known bug and they have a fix for 6.2. The exception is hiding a deeper problem that may be difficult to know without a proper stack trace. A workaround is to upgrade your Entity Framework to the latest 6.2 pre-release build and see what the real problem is then revert back to your current build, in my case it was 6.1.3


  1. 从Entity Framework 6.2获取最新的签名版本。您将需要添加NuGet存储库。 https://www.myget.org/F/aspnetwebstacknightly/。有关此步骤的详细说明,请参阅此处: https://github.com/aspnet/EntityFramework6 / wiki / Nightly-Builds

  2. 为您的解决方案打开NuGet软件包管理器

  3. 检查预发布复选框NuGet软件包管理器的顶部

  4. 在项目选择窗口中,选择引用实体框架的所有项目

  5. 在版本下拉列表中选择最新的6.2版本并点击安装按钮。这将卸载您当前的版本并安装预选版本

  6. 构建您的解决方案

  7. 打开包管理器控制台并输入命令更新数据库

  1. Get the latest signed build from Entity Framework 6.2. You will need to add the NuGet repository https://www.myget.org/F/aspnetwebstacknightly/ . Detailed instructions for this step can be found here: https://github.com/aspnet/EntityFramework6/wiki/Nightly-Builds
  2. Open the NuGet Package Manager for your solution
  3. Check the 'pre-release' checkbox at the top of the NuGet Package Manager
  4. In the project selection window select all of your project(s) that reference Entity Framework
  5. In the version dropdown select the latest 6.2 build and click the 'install' button. This will uninstall your current version and install the pre-release version selected
  6. Build your solution
  7. Open the Package Manager Console and enter the command Update-Database

此时您应该看到一个详细的错误消息它应该让你更好地了解你需要做什么来解决这个问题。在我的情况下,访问文件和Visual Studio需要以管理员身份运行时出现问题。

At this point you should see a detailed error message of what is wrong and it should give you a better idea of what you need to do to resolve the issue. In my case there was an issue with accessing a file and Visual Studio needed to be ran as an Administrator.

解决问题后,您可以撤消对实体的更改框架版本或按照上述步骤,但将您的版本更新为您使用的先前版本。

Once you resolve the issue you can either undo your changes to entity framework version or follow the steps above but updating your version to the previous version you were using.

这篇关于新的嵌入式Firebird,代码第一,EF6项目结果在SerializationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆