Masoud Masoud - 1 month ago 5
C# Question

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

I have a

WinForm
s 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?

hvd hvd
Answer

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 MS key"). The official instructions at Entity Framework's CodePlex page show how to disable strong name validation (run the EnableSkipStrongNames task, that is for example build.cmd /t:EnableSkipStrongNames), so that you can use the delay-signed assemblies without MS 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.