New embedded Firebird, code first, EF6 project results in SerializationException

烈酒焚心 提交于 2019-12-10 17:39:24

问题


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.

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.

My 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>

My 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...

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.


回答1:


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. 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

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.




回答2:


This is known issue in EF. It's fixed in not-yet-release 6.2.



来源:https://stackoverflow.com/questions/34959584/new-embedded-firebird-code-first-ef6-project-results-in-serializationexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!