A solution that uses EntityFramework source projects instead its assemblies, could not start successfully

1

I have a WinForms project that uses EntityFramework 6.1.2-beta with .NET4, it worked fine, till I decided to replace EF assemblies with their source codes, for some tracing goals, so I removed EntityFramework.dll and EntityFramework.SqlServer.dll from my project references and get their source codes from CodePlex and add them to my solution.

I changed these new project configuration to DebugNet40(because my project works with .NET 4, but EntityFramework and EntityFramework.SqlServer projects work with .NET 4.5).

It compile successfully, but now when I want to run my project I get following error:

An unhandled exception of type 'System.IO.FileLoadException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll

Additional information: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

It is my app.config file:

<?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" />
  </configSections>
  <entityFramework>
     <defaultConnectionFactory 
          type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 
                EntityFramework">
          <parameters>
             <parameter value="mssqllocaldb" />
          </parameters>
     </defaultConnectionFactory>
     <providers>
     <provider invariantName="System.Data.SqlClient" 
               type="System.Data.Entity.SqlServer.SqlProviderServices, 
               EntityFramework.SqlServer" />
     </providers>
  </entityFramework>
  <connectionStrings>
     <add name="ERPContext" 
                connectionString="Data Source=.;Initial Catalog=MyDb;
                Persist Security Info=True;User ID=sa;password=*****" 
                providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

I removed PublicKeyToken=b77a5c561934e089" from app.config too, but the problem exists yet.

Is there any Idea?

c#
entity-framework
configuration
.net-4.0
app-config
asked on Stack Overflow Oct 20, 2014 by Masoud • edited Jun 20, 2020 by Community

2 Answers

3

The Entity Framework source code is configured to produce delay-signed assemblies (which means they're marked as "should be signed in the future with the official key"). The official instructions at Entity Framework's GitHub page show how to disable strong name validation (run the EnableSkipStrongNames task: build /t:EnableSkipStrongNames), so that you can use the delay-signed assemblies without anyone having to release their private key. This is sufficient for development systems.

If you intend to release a product relying on your custom-built modified Entity Framework DLLs, you should generate a new key, and modify the EF source code to use that new key.

answered on Stack Overflow Oct 20, 2014 by (unknown user) • edited Oct 30, 2016 by (unknown user)
1

You can right click the project in Visual Studio solution explorer, and Signing on the left and uncheck sign assembly. In your web config you will also need to remove the public key token.

answered on Stack Overflow Jul 4, 2017 by Alexander Higgins

User contributions licensed under CC BY-SA 3.0