Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet restore failing for empty project under arm64 #8182

Closed
Yen opened this issue Nov 20, 2022 · 6 comments
Closed

dotnet restore failing for empty project under arm64 #8182

Yen opened this issue Nov 20, 2022 · 6 comments
Labels

Comments

@Yen
Copy link

Yen commented Nov 20, 2022

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!

@Yen
Copy link
Author

Yen commented Nov 20, 2022

Full .csproj for reference, using sdk 7.0.100.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

@uxsoft
Copy link

uxsoft commented Nov 21, 2022

Same issue here.

@rainersigwald
Copy link
Member

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).

@rainersigwald
Copy link
Member

Duplicate of NuGet/Home#12227

@rainersigwald rainersigwald marked this as a duplicate of NuGet/Home#12227 Nov 21, 2022
@rainersigwald rainersigwald closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
@Yen
Copy link
Author

Yen commented 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.

@rainersigwald
Copy link
Member

Ah sorry, this symptom is actually dotnet/runtime#78340 -- but still not in the MSBuild layer.

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants