.NET Core File Lock

I have an ASP.NET Core application. I launch the application by running the command

dotnet run 

I see the following error in one of five situations when creating this ASP.NET Core application.

C: ... \ error CS2012: Unable to open "C: ... \ bin \ Debug \ netcoreapp1.0 \ AAA.Web.dll" for writing - "The process cannot access the file" C: ... \ "bin \ Debug \ netcoreapp1.0 \ AAA.Web.dll 'because it is being used by another process.'

In addition to the above problem, I also do not see the updates I am doing in the CSHTML file. I have to stop dotnet run , build the application again, and then start dotnet run .

How can I fix these problems?

enter image description here

+26
source share
9 answers

It can also help when running an aspnetcore application in IIS.

Add the following to your csproj:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Exec Command="echo &quot;App Offline&quot; /a &gt; &quot;$(ProjectDir)app_offline.htm&quot;" /> </Target> <Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Exec Command="del &quot;$(ProjectDir)app_offline.htm&quot;" /> </Target> 
+14
source

If it is local, and the application runs on IIS, then the Windows taskbar must have the IIS Express option before the date and time. select IIS Express, select the output. Try to run the application again.

exit IIS Express

+11
source

The dotnet watch can track changes and changes to the file system and compile them into the current process. This is done by installing the Microsoft.DotNet.Watcher.Tools package in the tools section of the project.json file. See usage documentation here .

After installing it, you can start the application using the dotnet watch run and make changes, avoiding manually restarting the application.

+6
source

This has happened to me many times. The problem, at least in my case, was that I was running the application. Therefore, when the compiler tries to update the dll, this is not possible because the dll is blocked and used by the running application. As soon as I close the application and compile again, it works fine.

+3
source

In my case, the same problem arose because of the dotnet watch run command even after stopping watch mode.
Visual studio reported this error message: file locked: ".NET core Host (pid)"
Killing the process with pid solved the problem.

+3
source

I ended up redesigning the application pool to unlock my libraries. enter image description here

+3
source

This is the difference between compiled languages ​​like C and interpreted as python. Of course, they need to be compiled after the change. If you look at the assembly, the view will be the same as in the code, and can be updated on the fly, but dlls must be compiled.

+1
source

I might be a bit late for the party here, but for future people reading this question, it might seem like this is a bit of a β€œfeature” of how VS / core can interact with IIS and prevent file locking:

https://developercommunity.visualstudio.com/content/problem/546858/bin-files-locked-by-iis-worker-process-1.html

This is apparently being investigated and reviewed for .net core vnext.

+1
source

A workaround is better than restarting the computer - close VS , open the task manager and destroy all instances of VBCSCompiler.exe

It worked for me

0
source

Source: https://habr.com/ru/post/1263256/


All Articles