grpc: C#: Grpc.Core native libs copying blocked by IIS locking the files
What version of gRPC and what language are you using?
C#, Grpc.Core 2.26.0 , net472.
What operating system (Linux, Windows,…) and version?
Windows 10
What runtime / compiler are you using (e.g. python version or version of gcc)
.net 4.7.2, Visual Studio Build Tools 2017
What did you do?
I have a website using gRPC deplyed in IIS. While the application is running (i.e. has been accessed at least once), try to rebuild the application.
What did you expect to see?
Application should be built succesfully, and IIS reloads the site.
What did you see instead?
Tyring to rebuild the application (by msbuild, or ctrl + shift + b in visual studio) gets interrupted by:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4582,5):
error MSB3027: Could not copy "C:\Users\villevai\.nuget\packages\grpc.core\2.26.0\runtimes\win\native\grpc_csharp_ext.x64.dll" to "bin\grpc_csharp_ext.x64.dll".
Exceeded retry count of 10. Failed. The file is locked by: "IIS Worker Process (22268)" [C:\.... \Startup.csproj]
This doesn’t happen with managed libraries, as IIS doesn’t lock them.
Anything else we should know about your project / environment?
I am using Paket, which automatically imports the targets file from Grpc.Core nuget package: “packages\server\Grpc.Core\build\net45\Grpc.Core.targets”.
This file contains:
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx\native\libgrpc_csharp_ext.x86.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>libgrpc_csharp_ext.x86.dylib</Link>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx\native\libgrpc_csharp_ext.x64.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>libgrpc_csharp_ext.x64.dylib</Link>
<Visible>false</Visible>
</Content>
Ignoring the error if it happens here (as it will probably always happen because file is locked), or making it conditional on target file not existing would help here.
Changing to:
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
doesn’t seem to fix the problem, it still tries to copy the file.
I’m working around the issue by always recycling the IIS app pool before compilation, but that’s not optimal.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 19 (14 by maintainers)
how is this close when its still an issue am i missing something
@aburakab what @jtattermusch said. For illustrative purposes, I pushed an example msbuild file that “safely” copies the files to output dir: https://github.com/vivainio/GrpcNativeLibsCopier (using an own python script)
@aburakab the workaround provided in https://github.com/grpc/grpc/pull/22894 is not supposed to be a full fix. It just provides the
Grpc_SkipNativeLibsCopy
property (which you need manually set yourself if you choose to and you know what you’re doing - please doublecheck the comment) that allows you to skip copying the native libs altogether. https://github.com/grpc/grpc/issues/21867#issuecomment-625263256A workaround has been merged in https://github.com/grpc/grpc/pull/22894 There is not much we can do beyond that.
Would this get more traction if I provided a PR implementing SkipGrpcNativeLibsCopy toggle?
@vivainio I’m seeing the same thing. Version Grpc.Core 2.27.0 is also affected. The .net Core libraries don’t seem to have this issue.