Describe the bug
I'm having an issue building a project we've just added Refit too. It's specifically when running the build in TeamCity, making me think it's environmental but we've been looking at this all afternoon and haven't been able to find anything.
The following error is shown when running msbuild
[16:33:10] : [Step 4/10] Build FAILED.
[16:33:10] : [Step 4/10]
[16:33:10] : [Step 4/10] "E:\BuildAgent\work\[Removed]\[Removed].sln" (build target) (1) ->
[16:33:10] : [Step 4/10] "E:\BuildAgent\work\[Removed]\Android.Gui\Android.Gui.csproj" (default target) (2) ->
[16:33:10] : [Step 4/10] "E:\BuildAgent\work\[Removed]\Android.Service\Android.Service.csproj" (default target) (3:2) ->
[16:33:10] : [Step 4/10] (GenerateRefitStubs target) ->
[16:33:10] : [Step 4/10] C:\Users\buildadmin\.nuget\packages\refit\5.0.15\build\netstandard2.0\refit.targets(30,5): error : The type initializer for 'Roslyn.Utilities.TextKeyedCache`1' threw an exception. [E:\BuildAgent\work\[Removed]\Android.Service\Android.Service.csproj]
[16:33:10] : [Step 4/10]
[16:33:10] : [Step 4/10] 0 Warning(s)
[16:33:10] : [Step 4/10] 1 Error(s)
Steps To Reproduce
Expected behavior
Build to succeed same as when run locally
Environment
Does it repro with the latest version? How about with VS 2019?
I haven't tried building using another version of Visual Studio so far. I'm slightly reluctant to try this as its going to require a project migration and installing VS19 on the build server. We also only have licences for 2017 so ideally I'd like to keep it in 2017 if possible.
I can try this if you think it's necessary for debugging this. Or do you think down grading Refit would allow us to keep it in 2017?
As a starting point, it'd be useful to know if it repros or works with the latest Refit version. 5.1.x is the latest.
So I've upgrade Refit to 5.1.67 on my local machine. I'm now not able to build on there, but I am getting a different error though...
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I have tried manually referencing this package through Nuget, but there is no published 4.0.4.1 version in the feed. Shouldn't the dependency be resolved by the refit package anyway?
We're also getting the same error with 5.1.67 using VS 2019
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I catch this problem too
On local machine all right, and TeamCity build failed
Refit 5.1.67
TeamCity Ent 2019.2 build 71499
VS2019 16.2.5

We are also experiencing the same problem. The build locally works but on the build server we get the following error.
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Anyone has progress on this? Everything is fine when built with VS 2019 but that's not a solution for us for now, we need to be able to use VS 2017 as well, noticed this on our agent which uses 2017...
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Closing due to age. Please try Refit v6 and reopen if still an issue.
Most helpful comment
I catch this problem too

On local machine all right, and TeamCity build failed
Refit 5.1.67
TeamCity Ent 2019.2 build 71499
VS2019 16.2.5