arefinsami
arefinsami

Reputation: 363

Could not load file or assembly 'EntityFramework' or one of its dependencies

My ASP.NET MVC3 web application was working fine. but when i restarted my pc and then trying to update the application in MS VS 2010 it shows an error during running the application:

Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Description:

An unhandled exception occurred during the execution of the current web request. Please 
review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'EntityFramework' could not be loaded.

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:

[FileLoadException: Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]

[FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591

[HttpException (0x80004005): Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

Then i clear all windows temp file and ASP.NET temp file then run the application again. but situation is not improved. Could you please help me to solve this.Thank you.

Upvotes: 8

Views: 39668

Answers (5)

Mac
Mac

Reputation: 369

I was getting this error. The cause turned out to be simpler than some of the other answers: I had two projects that referenced different versions of Entity Framework. One came from a NuGet package that contained the latest version, and the other was from the ASP.NET MVC 4 template.

My fix was to remove the reference to the older version of EF (5) from the MVC 4 project and install the latest with NuGet. Everything ran fine after that.

Upvotes: 3

Matty J
Matty J

Reputation: 3156

If none of the other answers work for you (including answers to other similar questions on SO about this same problem), try the following which worked for me (as per http://forums.devart.com/viewtopic.php?f=3&t=26327):

Add the following XML in the *.config file of your application to solve the problem:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
      <bindingRedirect oldVersion="4.4.0.0" newVersion="5.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
  </runtime>

Upvotes: 14

JGilmartin
JGilmartin

Reputation: 9298

Make sure that all the projects are targeting the same .NET Framework. I have a .NET 4.5 project that was referencing a class library that is using 4.0 and I was getting this issue, once I changed it to 4.5 it worked fine and I could install EF using NuGet Package Manager Console

Upvotes: 8

cjbarth
cjbarth

Reputation: 4469

I had a similar problem and I had to manually delete the package folder in my solution and the reference to the package in the packages.config file and then reinstall it using the Package Manager Console to fix it.

Upvotes: 2

Adam Tuliper
Adam Tuliper

Reputation: 30142

Simply re-add entity framework Tools-library Package Manager->Package Manager Console

Type:

Install-Package EntityFramework

It will restore (you are running v 4.4, which is the v5 version in Visual studio 2010)

If you want to be 'clean' you can try an uninstall first. There's no harm in this even if it fails.

Uninstall-Package EntityFramework

Upvotes: 14

Related Questions