I can't seem to find this issue anywhere, probably because it is so generic.
I created an empty asp.net web application in visual studio 2017 community edition. The application is named AMS.
When I debug, I get the following error:
Could not load file or assembly 'AMS' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
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 'AMS' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
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 'AMS' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = AMS
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: AMS | 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:/Save_Here/Development/AMS/AMS/AMS/
LOG: Initial PrivatePath = C:\Save_Here\Development\AMS\AMS\AMS\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Save_Here\Development\AMS\AMS\AMS\web.config
LOG: Using host configuration file: C:\Users\Zalmy\Documents\IISExpress\config\aspnet.config
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:/Users/Zalmy/AppData/Local/Temp/Temporary ASP.NET Files/vs/790b60e8/774f1d4b/AMS.DLL.
LOG: Attempting download of new URL file:///C:/Users/Zalmy/AppData/Local/Temp/Temporary ASP.NET Files/vs/790b60e8/774f1d4b/AMS/AMS.DLL.
LOG: Attempting download of new URL file:///C:/Save_Here/Development/AMS/AMS/AMS/bin/AMS.DLL.
LOG: Using application configuration file: C:\Save_Here\Development\AMS\AMS\AMS\web.config
LOG: Using host configuration file: C:\Users\Zalmy\Documents\IISExpress\config\aspnet.config
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).
ERR: Failed to complete setup of assembly (hr = 0x80070020). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'AMS' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
[FileLoadException: Could not load file or assembly 'AMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'AMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531
[HttpException (0x80004005): Could not load file or assembly 'AMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963856
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
The app is very simple so far. I got packages from NuGet for Identiy, EntityFramework, Owin, Owin.Host.SystemWeb, Owin.Security, and Owin.Security.Cookies. I have a single empty javascript file, a single short CSS file, and Login and Register aspx page tied to a single MasterPage file which has links to the CSS file and to Google's content delivery network of a JQuery file in the head section. I also created one Startup.vb which loads up the OwinStartup assembly and configures the app to use Cookie authentication.
My web.config file looks like this:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=Zalmy-PC;Initial Catalog=AMS;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
I have tried so many things: restarting, reinstalling Visual Studio 2017, creating the project from scratch again and copying/pasting the content, running in Administrator, cleaning, rebuilding, changing target CPU. The strange part is that it works sometimes if I refresh the page a bunch of times or if I restart debugging a bunch of times, but sometimes I can never get it to work. And I can't seem to make anything of the log/stack trace.
I should note that I have VS2010 Pro, VS2012 Pro, and VS2015 Community also installed on my computer.
If it helps, my PC is an AMDx64, Windows 7.
Thanks in advance!
Some referenced Nuget packages can reference different versions of the same assembly. In such situations you can even successfully build the solution but start getting errors when debugging. Some referenced Nuget packages can miss required external dependecies in the package description - and they are not installed automatically. There is no universal solution to this issue except thorough analysis what assemblies are referenced and what are missed/conflicted.
You may found useful a tool I made for this type of analysis: http://www.marss.co.ua/2017/05/reference-conflicts-analyzer-visual.html
Just select dll your web application built in (I assume it should be AMS.dll) and the corresponding web.config and you will get all referenced assemblies.
User contributions licensed under CC BY-SA 3.0