System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks'
Turnerj opened this issue · comments
Hey! I'm trying to get Incrementalist working on Azure DevOps and am hitting some issues running it. I get the following error running it:
fail: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Msbuild failed when processing the file '/home/vsts/work/1/s/path/to/my/proj.csproj' with message: /opt/hostedtoolcache/dotnet/sdk/6.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets: (90, 5): The "ProcessFrameworkReferences" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.1.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
File name: 'NuGet.Frameworks, Version=6.2.1.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.1.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
I get this error for probably every project in the solution with also these warnings randomly scattered throughout:
warn: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Found project reference without a matching metadata reference: /home/vsts/work/1/s/another/path/to/a/project.csproj
After all the warnings and errors, it does complete with:
No changes detected by Incrementalist when analyzing solution.
This is correct for the PR as there were no changes besides some YAML to actually do the incremental building etc.
Some things to know about the environment:
- .NET SDK 6.0.303
- All projects target .NET 6 (except some source generators which target .NET Standard 2.0)
- There are over 400 projects in the solution
- Azure DevOps OS is Ubuntu 20.04.5 LTS
For the task that triggers Incrementalist, I am using the following code:
dotnet tool install --global Incrementalist.Cmd
echo "PR Target Branch: $SYSTEM_PULLREQUEST_TARGETBRANCH"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch origin --depth=1 $SYSTEM_PULLREQUEST_TARGETBRANCH
localTargetBranch=$(echo $SYSTEM_PULLREQUEST_TARGETBRANCH | sed 's/refs\/heads\///g')
echo "PR Local Target Branch: $localTargetBranch"
affectedProjects=$(~/.dotnet/tools/incrementalist -s ./my/solution.sln -b $localTargetBranch | sed 's/\n/,/g')
if [ "$affectedProjects" = "" ];
then
echo "No projects have changed - defaulting to build and test entire solution."
else
echo "##vso[task.setvariable variable=targetProjects;]$affectedProjects"
echo "Affected projects from PR: $affectedProjects"
fi
Additional note: Running just ~/.dotnet/tools/incrementalist -s ./my/solution.sln -b $localTargetBranch
locally via Powershell on Windows 10 (not WSL) produces the same errors though completes with changes (guessing it detected some whitespace/new line changes between Windows and Linux etc).
Hmmmm.... not sure what the issue could be here off the top of my head. We're going to push an update to Incrementalist soon to resolve some build issues with Akka.NET: akkadotnet/akka.net#6263
Do you still need help with this?
Yeah, it is some real funky behaviour. Happy to wait till you've got your update to Incrementalist in and try again then, maybe whatever anomaly that was causing the problem will go away.
If you happen to have any ideas between now and then though, happy to try them out too or if there is any more debugging output I can try and get out.
So these errors:
warn: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Found project reference without a matching metadata reference: /home/vsts/work/1/s/another/path/to/a/project.csproj
These are raised by Roslyn during analysis of individual projects - nothing to worry about there as far as I know. We get these on Akka.NET, Phobos, and Sdkbin all the time too when we run this on those projects and the diff detection still works fine.
As for:
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Msbuild failed when processing the file '/home/vsts/work/1/s/path/to/my/proj.csproj' with message: /opt/hostedtoolcache/dotnet/sdk/6.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets: (90, 5): The "ProcessFrameworkReferences" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.1.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
File name: 'NuGet.Frameworks, Version=6.2.1.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.1.7, Cu
Let me see if we get any of these - Roslyn throws out a lot of false negatives and that might have to do with the way we're calling it but the tool has worked consistently well for us for years.
Hmmm, so I'm not seeing any errors like this on Akka.NET anymore (although we used to) - but we're also using an older version of the .NET 6 SDK (6.0.100).
Let me try upgrading this project (before we do the upgrade to .NET 7.0) and see if that changes anything.
On #218
I'm now seeing the following:
fail: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Msbuild failed when processing the file '/home/vsts/work/1/s/src/Incrementalist.Tests/Incrementalist.Tests.csproj' with message: /opt/hostedtoolcache/dotnet/sdk/3.1.105/Microsoft.Common.CurrentVersion.targets: (1653, 5): Project '../Incrementalist.Cmd/Incrementalist.Cmd.csproj' targets 'net6.0;net5.0;netcoreapp3.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v5.0'.
fail: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Msbuild failed when processing the file '/home/vsts/work/1/s/src/Incrementalist.Tests/Incrementalist.Tests.csproj' with message: /opt/hostedtoolcache/dotnet/sdk/3.1.105/Microsoft.Common.CurrentVersion.targets: (1653, 5): Project '../Incrementalist.Cmd/Incrementalist.Cmd.csproj' targets 'net6.0;net5.0;netcoreapp3.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v5.0'.
warn: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Found project reference without a matching metadata reference: /home/vsts/work/1/s/src/Incrementalist.Cmd/Incrementalist.Cmd.csproj
warn: Incrementalist[0]
Issue during solution loading: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace: Found project reference without a matching metadata reference: /home/vsts/work/1/s/src/Incrementalist/Incrementalist.csproj
No changes detected by Incrementalist when analyzing solution.
Running Incrementalist folders-only check
So yes, it seems that the .NET SDK version has a big impact here.
Although I should comment - despite these errors the solution analysis still works. So this issue might be a "won't fix" since it doesn't seem to materially affect Incrementalists' ability to do its job. Can you try running Incrementalist on a PR with real changes @Turnerj and see if it works as expected?
Thanks for looking into this @Aaronontheweb - yeah, it looks like Incrementalist is actually behaving correctly. Tested it with few changes, lots of changes and no changes.
One thing I just realised (big face palm moment) is that I'm piping the output which would include the log messages - no wonder I'm hitting issues! 🤦♂️