33

I am consistently getting this error with VS 2013:

Could not copy "C:\pagefile.sys" to "bin\roslyn\pagefile.sys". Exceeded retry count of 10. Failed. Unable to copy file "C:\pagefile.sys" to "bin\roslyn\pagefile.sys". The process cannot access the file

Please help me.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
Pramod Raut
  • 677
  • 3
  • 9
  • 22
  • 1
    Make sure C:\pagefile.sys exists or not in use. – Dr. Stitch May 25 '16 at 05:31
  • Pretty bizarre error, copying the paging file is never possible. It never makes sense to try, Roslyn certainly does not do this. Fix your project. – Hans Passant May 25 '16 at 07:30
  • 1
    Finally found the answer from this post - http://stackoverflow.com/a/32784349/5470285 – Pramod Raut May 25 '16 at 08:44
  • I had similar problem with VS 2019 16.8.4, I had 2 work around. --> Downgraded to VS 2019 16.7.7 --> Moved VS solution and project to the first level folder to reduce the path length. – Varun Jan 29 '21 at 14:03

8 Answers8

51

As indicated in this answer from Pramod's comment the problem stems from the Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package, specifically upgrading from version 1.0.0 to 1.0.1.

For me however, downgrading using Visual Studio caused further build errors. To solve the problem I had to manually edit my csproj and packages.config files, removing all references to Microsoft.Net.Compilers and Microsoft.CodeDom.Providers.DotNetCompilerPlatform.

Specifically, this meant:

  • Removing the relevant <Import Project="... sections for all versions of both libraries (usually towards the beginning of the csproj)
  • Removing the <Reference Include="... sections for both versions of both libraries
  • Removing the <Error Condition="!Exists(... sections for both versions of both libraries from within the EnsureNuGetPackageBuildImports target section
  • Removing all Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers packages from the packages.config.

I was then able to manage the projects nuget packages in VS and (in order) :

  • Add Microsoft.Net.Compilers version 1.2.2
  • Add Microsoft.CodeDom.Providers.DotNetCompilerPlatform version 1.0.1

This solved the pagefile build error, and the runtime error which prompted me to try and upgrade in the first place.

Community
  • 1
  • 1
T S Taylor
  • 1,501
  • 1
  • 14
  • 16
  • Following this is the only thing that worked for me. Also, instead of getting 1.2.2 of Microsoft.Net.Compilers I got 1.3.2 and things worked fine as well. – Adam Sep 06 '16 at 19:49
  • Also happens upgrading from version 1.3.2 to 2.4.0 probably because some library get into the cache. – Cairo Nov 14 '17 at 10:46
10

I removed these packages from nuget package manager since I do not use them:

  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform

  • Microsoft.Net.Compilers

Now everything works.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
toha
  • 5,095
  • 4
  • 40
  • 52
4

I've found a different solution to this error. In my case I had been moving around a project within my solution (I put it in a subfolder). My references to packages (located in %solutionfolder%/packages) in the project file were broken and I fixed them manually.

However, there are two supplement imports that I forgot:

  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />

I first updated the first one from ..\packages to ..\..\packages (lazy as I am). Building the project after that gave me the pagefile.sys error.

Updating the second import (same change: ..\packages to ..\..\packages) solved it for me.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
3

Using the Clean Solution/Rebuild Solution steps resolved this issue for me.

Granicus
  • 854
  • 10
  • 19
1

Remove these two lines from .csproj file:

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
osman
  • 43
  • 7
0

I delete this line in .csproj file

<Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />

And worked to me.

I use Visual Studio 2019, and I don't know why apears suddenly this error in my project.

0

This error went away for me when I quit the process of running my app in Windows PowerShell then restarted it.

-1

Not much to go off of, but I would suggest recording your issue using SysInternals Process Monitor

Once you have procmon running, you want to record (or trace, in other words) your issue with VS2013. Once you're done recording, you'll want to filter the results by process (in your case, devenv.exe), so press Ctrl-T to open the Process Tree, and find devenv.exe.

Select it, and then click the "Include Subtree" button. Close the Process Tree window, and select Tools -> Count Occurrences from the top menu. Set the Column dropdown box to 'Result' and press the Count button. The output will be a collection of results along with their respective counts. You can usually get a good idea of what's going on by looking at these results. For example, if you see a lot of results involving ACCESS DENIED or FILE LOCKED WITH ONLY READERS, then most likely your issue is related to permissions.

zx485
  • 28,498
  • 28
  • 50
  • 59
Bertholt
  • 81
  • 1
  • 8