`dotnet restore` failing for empty project under arm64

See original GitHub issue

I’m using docker buildx to build under and emulated arm64 environment, this may be a bug with buildx instead, but I do not have a native arm64 environment to test on and the error occurs inside msbuild.

 => ERROR [4/4] RUN dotnet restore                                                                                                                                                                                                   7.5s
------                                                                                                                                                                                                                                    
 > [4/4] RUN dotnet restore:                                                                                                                                                                                                              
#0 7.274 MSBUILD : error : This is an unhandled exception in MSBuild -- PLEASE UPVOTE AN EXISTING ISSUE OR FILE A NEW ONE AT https://aka.ms/msbuild/unhandled. [/source/CrashSample.csproj]                                               
#0 7.274 MSBUILD : error :     System.NullReferenceException: Object reference not set to an instance of an object. [/source/CrashSample.csproj]                                                                                          
#0 7.274 MSBUILD : error :    at Regex1_Scan(RegexRunner, ReadOnlySpan`1) [/source/CrashSample.csproj]                                                                                                                                    
#0 7.274 MSBUILD : error :    at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan`1 span, Boolean returnNullIfReuseMatchObject) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String inputString, ReadOnlySpan`1 inputSpan, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunnerMode mode, Boolean reuseMatchObject) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String input, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunnerMode mode, Boolean reuseMatchObject) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Text.RegularExpressions.Regex.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ItemExpander.IntrinsicItemFunctions`1.ExpandQuotedExpressionFunction(Expander`2 expander, IElementLocation elementLocation, Boolean includeNullEntries, String functionName, IEnumerable`1 itemsOfType, String[] arguments)+MoveNext() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ItemExpander.Transform[S](Expander`2 expander, Boolean includeNullEntries, Stack`1 transformFunctionStack, IEnumerable`1 itemsOfType)+MoveNext() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ItemExpander.Transform[S](Expander`2 expander, Boolean includeNullEntries, Stack`1 transformFunctionStack, IEnumerable`1 itemsOfType)+MoveNext() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ItemExpander.ExpandExpressionCapture[S](Expander`2 expander, ItemExpressionCapture expressionCapture, IItemProvider`1 evaluatedItems, IElementLocation elementLocation, ExpanderOptions options, Boolean includeNullEntries, Boolean& isTransformExpression, List`1& itemsFromCapture) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ItemExpander.ExpandExpressionCaptureIntoItems[S,T](ItemExpressionCapture expressionCapture, Expander`2 expander, IItemProvider`1 items, IItemFactory`2 itemFactory, ExpanderOptions options, Boolean includeNullEntries, Boolean& isTransformExpression, IElementLocation elementLocation) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.LazyItemEvaluator`4.IncludeOperation.SelectItems(Builder listBuilder, ImmutableHashSet`1 globsToIgnore) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemOperation.ApplyImpl(Builder listBuilder, ImmutableHashSet`1 globsToIgnore) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemOperation.Apply(Builder listBuilder, ImmutableHashSet`1 globsToIgnore) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemList.ComputeItems(LazyItemList lazyItemList, ImmutableHashSet`1 globsToIgnore) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemList.GetItemData(ImmutableHashSet`1 globsToIgnore) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visualStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.BackEnd.BuildRequestConfiguration.<>c__DisplayClass60_0.<LoadProjectIntoConfiguration>b__0() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.BackEnd.BuildRequestConfiguration.InitializeProject(BuildParameters buildParameters, Func`1 loadProjectFromFile) [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.BuildProject() [/source/CrashSample.csproj]
#0 7.274 MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.BuildAndReport() [/source/CrashSample.csproj]

Steps to reproduce:

  1. dotnet new console -o CrashSample
  2. cd CrashSample
  3. touch Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0
WORKDIR /source
COPY *.csproj .
RUN dotnet restore
  1. docker buildx build . --platform linux/arm64

Attempting the same build without buildx or buildx specifying linux/amd64 both run to completion.

Also, to note, this build fails with a different error when building against platform linux/arm/7. This error is not an msbuild unhandled exceptions so might not fit into the same category as above, but might be of use figuring out what’s going on.

 > [4/4] RUN dotnet restore:                                                                                                                                                                                                              
#0 4.280 /usr/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: The expression "[MSBuild]::GetTargetFrameworkVersion(net7.0, 2)" cannot be evaluated. Exception has been thrown by the target of an invocation. [/source/CrashSample.csproj]

Thanks!

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rainersigwaldcommented, Nov 21, 2022

Ah sorry, this symptom is actually https://github.com/dotnet/runtime/issues/78340 – but still not in the MSBuild layer.

0reactions
Yencommented, Nov 21, 2022

Thanks for the report. We’re tracking this in the NuGet repository at the moment (MSBuild calls into NuGet APIs on that codepath, and they’re what seems to be going wrong).

Just to be clear, the issue occurs from nuget, but this is a null reference exception and presumably still a bug in msbuild if an incorrect invocation of msbuild crashes like this. Unsure how you prioritise these sort of issues, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net core - dotnet restore fails from Docker container
The actual error seems to be: Unable to load the service index for source https://api.nuget.org/v3/index.json.
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
In this case, run msbuild -t:restore followed by msbuild , or use dotnet build (which restores packages automatically).
Read more >
Containerize a .NET app with dotnet publish
In the working folder, run the following command to create a new project in a subdirectory named Worker: .NET CLI
Read more >
Error running MAUI on iOS Device - Microsoft Q&A
Hi, I have just downloaded Visual Studio for Mac PRE 17.3 (Build 1038) but when I try to run the default MAUI app...
Read more >
NETSDK1005 and NETSDK1047: Asset file is missing target
NET SDK issues error NETSDK1005 or NETSDK1047, the project's assets file is missing information on one of your target frameworks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found