MSBuild with target netfx48 temp files present fails with Missing Method.
See original GitHub issueIssue Description
Using a roslyn CodeAnalysis project running on net48 attempting to load a project also targetting net48 will fail to load dependencies caused by a missing method Method not found: 'System.ReadOnlySpan`1<Char> Microsoft.IO.Path.GetFileName(System.ReadOnlySpan`1<Char>)' if the target project has already been compiled and has bin/obj directories present.
Steps to Reproduce
CodeAnalysisApp2.zip Repro is attached. To use
- unzip and open the
CodeAnalysisApp2.slnfile then run it. It should load the console app solution and correctly run through to the console readline without displaying any problems. - open the
ConsoleApp2.slnand compile or run it - reopen the
CodeAnalysisApp2.slnand run it again, you should get an error:
Using MSBuild at 'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin' to load projects.
Loading solution '..\..\..\..\ConsoleApp2.sln'
Evaluate 0:00.2464048 ConsoleApp2.csproj
Msbuild failed when processing the file 'D:\Programming\csharp10\CodeAnalysisApp2\ConsoleApp2\ConsoleApp2.csproj' with message: Method not found: 'System.ReadOnlySpan`1<Char> Microsoft.IO.Path.GetFileName(System.ReadOnlySpan`1<Char>)'.
Finished loading solution '..\..\..\..\ConsoleApp2.sln'
Versions & Configurations
Latest VS 17.3 update, this worked on 17.2. MSBuild version 17.3.0+f67e3d35e for .NET Framework 17.3.0.37102
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Daniel Cazzulino's Post - dotnet/msbuild
TIL: Missing Method exceptions during test runs (i.e. in #nugetizer) can be fixed by bumping to #msbuild 17.3.1: MSBuild with target netfx48 temp...
Read more >System.Memory.dll issue - Rhino Developer - McNeel Forum
MSBuild with target netfx48 temp files present fails with Missing Method. opened 10:12PM - 10 Aug 22 UTC. Wraith2. bug Documentation Breaking ...
Read more >MSBuild fails due to missing files - that I actually want to ...
I'm attempting to set up a Continuous Integration process for a legacy VB.Net ASP.Net Forms application, using Visual Studio 2015 and an on ......
Read more >Fix intermittent build failures
Learn how to diagnose and fix race conditions in your MSBuild parallel builds.
Read more >MSB6003: The specified task executable ...
This error indicates that an executable that was part of the build process could not be executed. There is usually an additional error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the repro project, that plus another nice repo from a Microsoft-internal person really helped me understand what’s going on here, which is this:
System.Memory 4.0.1.1to be loaded.System.Memory 4.0.1.2, which is located and loaded by Locator.https://github.com/dotnet/msbuild/blob/92e0776509a23ed2c1e24bf906a92f045899b885/src/Shared/FileMatcher.cs#L1653-L1663
which compiles down to this IL for our net472 target:
System.MissingMethodException: 'Method not found: 'System.ReadOnlySpan`1<Char> Microsoft.IO.Path.GetFileName(System.ReadOnlySpan`1<Char>)'.'Microsoft.IO.Redist.dlldepends onSystem.Memory 4.0.1.1(it is unchanged butSystem.Memoryhas a new version)[System.Memory 4.0.1.1] System.ReadOnlySpan`1<char>, but the type we need in Microsoft.Build is a[System.Memory 4.0.1.2] System.ReadOnlySpan`1<char>(because that was the winning version in our build).MissingMethodExceptionis thrown: no method found matching that (version of) that type in its signature.MSBuild.exeoperation, because we have binding redirects in place that ensure that allSystem.Memorytypes are 4.0.1.2:https://github.com/dotnet/msbuild/blob/92e0776509a23ed2c1e24bf906a92f045899b885/src/MSBuild/app.amd64.config#L85-L86
Tactically, there are two fixes that can be applied:
System.Memoryto version 4.5.5 and binding redirect to it a. This may require adding the reference explicitly; it was likely transitive before b. Updating MSBuild references to 17.3 will do this automatically since that package depends on 4.5.5. c. You probably don’t need to do binding redirects manually because they should be automaticSystem.Memory.dllfrom the application directory a. This causes Locator to find the System.Memory that lives in MSBuild, which will be the correct version for MSBuild. b. If that version is the only version that can be loaded, the .NET Framework (essentially) binding-redirects all references to that version, so everything sees 4.0.1.2 and is consistent c. This can be nontrivial since it’s coming to the app’s output folder as a transitive reference. d. This also requires that MSBuildLocator be called before using anySystem.Memorytypes, which is stricter than was required before.Were either of rainersigwald’s mitigations helpful: https://github.com/dotnet/msbuild/issues/7873#issuecomment-1227332842 ?