Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yet another Could not load file or assembly 'EntityFramework

Now, I promise that I've googled this. Stack overflow has about 4 or 5 solutions to this issue. Still, none of them seem to be working. I'm using EntityFramework 5 (4.4) with an MVC 3 project. This has worked fine in the past, but it's been a while since I've opened the project (about 20 days or so). I've just uninstalled & reinstalled Sql Server 2008 R2 Express. I've rebooted since then.

In all of my cshtml files I see an error underlineline on my @model line. When I mouse over it, I see the following:

ASP.NET runtime error: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicTokenKey=b77a5c561934e089' or one of its dependencies. Access is denied.

I have uninstalled and re-installed the EntityFramework package via package manager console. I've done it via nuget as well. I've closed and re-opened visual studio. I've removed the reference and added it manually via browsing for the dll.

My web.config entry for this looks like:

[open tag]section name="entityFramework" type="System.Data.Entity, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" [close tag]

Any one have any thoughts?

EDIT 1 FULL ERROR DETAIL

Server Error in '/' Application.

Could not load file or assembly 'EntityFramework' or one of its dependencies. Access is denied.

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. Access is denied.

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.


=== Pre-bind state information ===
LOG: User = Unknown
LOG: DisplayName = EntityFramework
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: EntityFramework | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/MercurialProjects/ProxySetup/ProxySetup/
LOG: Initial PrivatePath = C:\MercurialProjects\ProxySetup\ProxySetup\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MercurialProjects\ProxySetup\ProxySetup\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/014aecc8/d1c2eaf7/EntityFramework.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/014aecc8/d1c2eaf7/EntityFramework/EntityFramework.DLL.
LOG: Attempting download of new URL file:///C:/MercurialProjects/ProxySetup/ProxySetup/bin/EntityFramework.DLL.
LOG: Using application configuration file: C:\MercurialProjects\ProxySetup\ProxySetup\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.

Stack Trace: 


[FileLoadException: Could not load file or assembly 'EntityFramework' or one of its dependencies. Access is denied.]

[FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Access is denied.]
   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. Access is denied.]
   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) +677

[HttpException (0x80004005): Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Access is denied.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090988
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

EDIT 2

Per the debug information above, I manually added all the dll's the application uses to the C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\014aecc8\d1c2eaf7 folder as that's what was eventually referenced as the error kept changing.

I don't see an ASPNET user to assign permissions to for the C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ directory. I've added: IUSR, NETWORK, NETWORK SERVICE, IIS_USRS (\IIS_ISURS) with full control. I'm still getting the error.

As I was still getting Access Denied for errors, I gave Users full control of the folder on my machine. The application loads. So...this is a permission error. The question is, what account needs the permissions?

like image 383
jason Avatar asked Nov 04 '22 06:11

jason


1 Answers

This may seems strange, but after running into this issue, and issues like this, I've identified two possible causes that are very much out of the norm.

1) if you're using chrome, make sure chrome is closed when you try to build your solution (I assume your not able to build the solution as a result of this error?). I know this sounds crazy, but I've found that sometimes, for whatever reason, certain files become inaccessible when I'm using chrome during development. I still don't know why, but it's worth a shot if you haven't been able to resolve the issue.

2) In your nuget package manager, if you haven't already reinstalled the entity framework, uninstall it, and reinstall it. I've found that when I move an App from one machine to another, or I update it from version control, that the nuget packages get messed up somehow. Reinstalling seems to be the only thing to get it on track.

3) Regarding your permissions specific issue, I'm not convinced that is the issue, however, you whole app folder, and subfolders/files should have user "Everyone" set with full read/execut permissions (but NOT write permissions). That should be all you need regarding permissions (at least that's all I seem to need during setup).

good luck.

like image 119
Scott Terry Avatar answered Nov 08 '22 04:11

Scott Terry