question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Builds of solutions with multiple inter-dependent .NET Core projects frequently fail with CS2012 "Cannot open" file errors

See original GitHub issue

Steps to reproduce

With a solution with multiple .NET Core projects with many sharing project dependencies:

  • dotnet restore
  • dotnet build

Expected behavior

Solution builds.

Actual behavior

Solution sometimes builds, but also often fails with errors similar to:

CSC : error CS2012: Cannot open 'C:\a\w\1\s\src\Project\obj\Debug\netstandard1.4\Project.dll' for writing -- 'The process cannot access the file 'C:\a\w\1\s\src\Project\obj\Debug\netstandard1.4\Project.dll' because it is being used by another process.'

Sometimes there are warnings:

warning MSB3026: Could not copy "obj\Debug\netstandard1.4\Project.dll" to "bin\Debug\netstandard1.4\Project.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\a\w\1\s\src\Project\bin\Debug\netstandard1.4\Project.dll' because it is being used by another process. [C:\a\w\1\s\src\Project\Project.csproj]

Errors and warnings can occur for different projects.

Switching from dotnet build to msbuild /maxcpucount:1 avoids the problems.

The errors occur more frequently on build servers (Azure VMs, Standard F2S) than on laptop (i7-5600U, 16GB, SSD).

Our build script replaces version numbers in AssemblyInfo.cs files, so many projects are rebuilt on every build.

Executing dotnet build --no-incremental also seems to increase failure rate locally (where otherwise repeated builds may not build all projects).

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview3-004056)

Product Information:
 Version:            1.0.0-preview3-004056
 Commit SHA-1 hash:  ccc4968bc3

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
sherlock1982commented, Nov 7, 2017

Well it’s really easy to reproduce with NET SDK 2.0.2

dotnet publish -o /home/user/publish_dir 

Will publish everything from a solution into one folder in case argument of -o is an absolute directory. This is super convenient and a way to go in case you make sure projects are compatible. Though publish commands can fight for files of course.

2reactions
benyitzhakicommented, Jun 24, 2018

this still occurs in 2.1.1, linux. fails sometimes when running the dotnet test, happens mostly on our builder machine but not only

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet build CS2012 cannot open dll for writing
I have a .Net Core 3.1 DLL project that all of a sudden didn't build anymore with the following error message: CSC :...
Read more >
Builds of solutions with multiple inter-dependent .NET Core ...
Builds of solutions with multiple inter-dependent .NET Core projects frequently fail with CS2012 "Cannot open" file errors.
Read more >
CSC : error CS2012: Cannot open 'File name and path' for ...
This has been an intermittent problem that appears to be worsening. We are using MSBuild via dotnet.exe. These builds are all .NET Core....
Read more >
CS2012 "cannot open" an executable "for writing"
Various error messages are propping up, sometimes with code CS2012. The two errors are either (1) The application EXE files fails to copy ......
Read more >
Problem: error CS2012
Hello everyone I am new to mono game and am trying to create a 2d platformer. Everytim I try and run the debugger...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found