Closed mthalman closed 1 year ago
See the original issue at https://github.com/dotnet/sdk/issues/28971 for more details.
Issue is missing Type label, remember to add a Type label
@BenVillalobos @rainersigwald Did you try reproing with a private MSBuild to get the whole stack?
@mthalman to help me be able to repro and investigate, could you please send the docker file and the project that you show above? Thanks!
That's not my project. It's from @zimbres that originally logged this that I copied it from.
I'm posting my repro project. I don't get the same exception stack as the OP but I get a crash.
To repro, just run docker build --platform linux/arm64 .
from the extracted directory. You can also replace linux/arm64
with linux/arm
and that will give you the Arm32 scenario which does sometimes give me the same as exception as @zimbres provided but other times a different exception.
Hello, no need specific code do reproduce, in my case, from VS17.4, creating a Worker Service for .NET7.0 with Docker support and try to build with:
docker buildx build --platform linux/arm64 -t zimbres/workerservice1 -f .\WorkerService1\Dockerfile --push . --no-cache
Docker file is the one auto generated by VS template:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["WorkerService1/WorkerService1.csproj", "WorkerService1/"]
RUN dotnet restore "WorkerService1/WorkerService1.csproj"
COPY . .
WORKDIR "/src/WorkerService1"
RUN dotnet build "WorkerService1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WorkerService1.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WorkerService1.dll"]
Same problem happening in Github Actions when we use QEMU to build ARM64 images. It appears to be failing inconsistently (one out of every 4-5 builds ends up working).
@donnie-msft I have not, I'm attempting to repro now using @mthalman 's repro and I do see the NRE related to regex's.
In fact, repro'ing the scenario two comments up shows the same regex NRE. @zimbres what's the dockerfile associated with seeing
#0 10.13 /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. [/src/src/EspUpdater/EspUpdater.csproj]
Dockerfile is the one provided by VS template like this:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["src/EspUpdater/EspUpdater.csproj", "src/EspUpdater/"]
RUN dotnet restore "src/EspUpdater/EspUpdater.csproj"
COPY . .
WORKDIR "/src/src/EspUpdater"
RUN dotnet build "EspUpdater.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "EspUpdater.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EspUpdater.dll"]
Interesting, I don't see the intrinsic function failing so there's no call stack to gather there. If I can get a reliable repro for that, I'm happy to drop in custom bits to log extra details about what's going wrong with [MSBuild]::GetTargetFrameworkVersion
My repro:
mkdir webapi
cd webapi
dotnet new webapi
cmd: docker buildx build --platform linux/arm64 -t zimbres/espupdater -f webapi\Dockerfile --push . --no-cache
my slightly modified Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["webapi/webapi.csproj", "src/webapi/"]
RUN dotnet restore "src/webapi/webapi.csproj"
COPY . .
WORKDIR "/src/src/webapi"
RUN dotnet build "webapi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "webapi.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "webapi.dll"]
My fail stack:
> [build 4/7] RUN dotnet restore "src/webapi/webapi.csproj":
#0 8.202 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. [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : System.NullReferenceException: Object reference not set to an instance of an object. [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Regex1_Scan(RegexRunner, ReadOnlySpan`1) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan`1 span, Boolean returnNullIfReuseMatchObject) [/src/src/webapi/webapi.csproj]
#0 8.202 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) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String input, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunnerMode mode, Boolean reuseMatchObject) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at System.Text.RegularExpressions.Regex.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.Evaluation.Expander`2.MetadataExpander.ExpandMetadataLeaveEscaped(String expression, IMetadataTable metadata, ExpanderOptions options, IElementLocation elementLocation) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.Evaluation.Evaluator`4.EvaluateItemDefinitionElement(ProjectItemDefinitionElement itemDefinitionElement) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.Evaluation.Evaluator`4.EvaluateItemDefinitionGroupElement(ProjectItemDefinitionGroupElement itemDefinitionGroupElement) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() [/src/src/webapi/webapi.csproj]
#0 8.202 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) [/src/src/webapi/webapi.csproj]
#0 8.202 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) [/src/src/webapi/webapi.csproj]
#0 8.202 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) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.BackEnd.BuildRequestConfiguration.<>c__DisplayClass60_0.<LoadProjectIntoConfiguration>b__0() [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.BackEnd.BuildRequestConfiguration.InitializeProject(BuildParameters buildParameters, Func`1 loadProjectFromFile) [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.BackEnd.RequestBuilder.BuildProject() [/src/src/webapi/webapi.csproj]
#0 8.202 MSBUILD : error : at Microsoft.Build.BackEnd.RequestBuilder.BuildAndReport() [/src/src/webapi/webapi.csproj]
Interesting, I don't see the intrinsic function failing so there's no call stack to gather there. If I can get a reliable repro for that, I'm happy to drop in custom bits to log extra details about what's going wrong with
[MSBuild]::GetTargetFrameworkVersion
My repro:
mkdir webapi
cd webapi
dotnet new webapi
cmd:
docker buildx build --platform linux/arm64 -t zimbres/espupdater -f webapi\Dockerfile --push . --no-cache
my slightly modified Dockerfile:
What am I missing here? I'm trying to repro your issue on my local.
C:\12227\webapi> ls
Directory: C:\12227\webapi
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/14/2022 4:52 PM Controllers
d----- 11/14/2022 4:52 PM obj
d----- 11/14/2022 4:52 PM Properties
-a---- 11/14/2022 4:52 PM 127 appsettings.Development.json
-a---- 11/14/2022 4:52 PM 151 appsettings.json
-a---- 11/14/2022 4:52 PM 557 Program.cs
-a---- 11/14/2022 4:52 PM 255 WeatherForecast.cs
-a---- 11/14/2022 4:52 PM 408 webapi.csproj
C:\\12227\webapi> docker buildx build --platform linux/arm64 -t zimbres/espupdater -f webapi\Dockerfile --push . --no-cache
[+] Building 0.0s (0/0)
error: could not find webapi: CreateFile webapi: The system cannot find the file specified.
C:\12227\webapi>
You need to be on .sln folder:
docker buildx build --platform linux/arm64 -t zimbres/espupdater -f MyApp\Dockerfile --push . --no-cache
You need to be on .sln folder:
docker buildx build --platform linux/arm64 -t zimbres/espupdater -f MyApp\Dockerfile --push . --no-cache
I can repro it. I'll try to diagnose root cause later this week.
@zimbres Does this issue look connected to https://github.com/dotnet/sdk/issues/27190? I'm just asking because both of them says ARM, I didn't verify it.
I encountered a similar problem (Docker Buildx on GitHub Actions) with different error message: https://developercommunity.visualstudio.com/t/Cannot-build-Docker-image-for-arm64-afte/10193334
I encountered a similar problem (Docker Buildx on GitHub Actions) with different error message: https://developercommunity.visualstudio.com/t/Cannot-build-Docker-image-for-arm64-afte/10193334
Please upvote this issue, we prioritize issue based on user feedback.
@rainersigwald @nkolev92
Exception is coming here, should we move to msbuild repo for triage? https://github.com/dotnet/msbuild/blob/7037436dc4d2038407c8592b9e256f0cf777f20c/src/Build/BackEnd/Shared/BuildRequestConfiguration.cs#L469
Fyi @zimbres @BenVillalobos
@erdembayar how did you determine that?
@erdembayar how did you determine that?
If you look into this comment https://github.com/NuGet/Home/issues/12227#issuecomment-1314513843, then you'll see below in callstack, that matches with msbuild code.
@erdembayar that call stack is a different bug, tracked by https://github.com/dotnet/runtime/issues/78340. This bug is about the error
#0 10.13 /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. [/src/src/EspUpdater/EspUpdater.csproj]
That MSBuild property function is a pretty thin wrapper around a NuGet API, which is why we routed here.
@rainersigwald
Is there a way to the actual logs from the msbuild side?
It'd be really hard for us to investigate without a better stack trace.
I also recently came across an issue in attempting to upgrade to .NET 7 for my qemu cross-compile to arm64. My logs aren't exactly the same, instead they say:
Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (arm64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestEngine.ShouldRunInProcess(String runsettings, Boolean isParallelEnabled, Boolean isDataCollectorEnabled, List`1 testHostProviders)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestEngine.GetExecutionManager(IRequestData requestData, TestRunCriteria testRunCriteria, IDictionary`2 sourceToSourceDetailMap, IWarningLogger warningLogger)
at Microsoft.VisualStudio.TestPlatform.Client.TestPlatform.CreateTestRunRequest(IRequestData requestData, TestRunCriteria testRunCriteria, TestPlatformOptions options, Dictionary`2 sourceToSourceDetailMap, IWarningLogger warningLogger)
at Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers.TestRequestManager.RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar, TestPlatformOptions options, Dictionary`2 sourceToSourceDetailMap)
at Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers.TestRequestManager.RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLauncher3 testHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.RunTestsArgumentExecutor.RunTests(String runSettings)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.RunTestsArgumentExecutor.Execute()
at Microsoft.VisualStudio.TestPlatform.CommandLine.Executor.ExecuteArgumentProcessor(IArgumentProcessor processor, Int32& exitCode)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Executor.Execute(String[] args)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Program.Main(String[] args)
qemu: uncaught target signal 6 (Aborted) - core dumped
You can see that this change should have been just a drop-in replacement and you can see the bash script for the test that's failing here.
@rainersigwald
Is there a way to the actual logs from the msbuild side?
It'd be really hard for us to investigate without a better stack trace.
@rainersigwald can you help @nkolev92 move forward?
Several of us are experiencing this problem, which currently has no workaround, therefore, it is blocking.
I see the same Regex crash that @BenVillalobos did when I run on my Windows host. Trying on an Ubuntu 22.04 + docker-desktop 4.15.0-93002, I get a successful run. Does anyone have a reliable repo they control? If so can you share OS version, kernel version, QEMU version, and Docker version in addition to Dockerfile?
raines@raines001:~/nuget_crash$ sudo docker buildx build --platform linux/arm64 -t zimbres/workerservice1 .
[+] Building 74.5s (19/19) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:7.0 0.4s
=> [internal] load metadata for mcr.microsoft.com/dotnet/runtime:7.0 0.4s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/runtime:7.0@sha256:12d50 0.0s
=> [build 1/8] FROM mcr.microsoft.com/dotnet/sdk:7.0@sha256:c6c842af 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 872B 0.0s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/8] WORKDIR /src 0.0s
=> CACHED [build 3/8] COPY [WorkerService1/WorkerService1.csproj, Wo 0.0s
=> [build 4/8] RUN which dotnet 0.5s
=> [build 5/8] RUN dotnet restore "WorkerService1/WorkerService1.cs 15.9s
=> [build 6/8] COPY . . 6.1s
=> [build 7/8] WORKDIR /src/WorkerService1 0.2s
=> [build 8/8] RUN dotnet build "WorkerService1.csproj" -c Release 33.6s
=> [publish 1/1] RUN dotnet publish "WorkerService1.csproj" -c Rele 16.6s
=> [final 2/2] COPY --from=publish /app/publish . 0.3s
=> exporting to image 0.7s
=> => exporting layers 0.7s
=> => writing image sha256:3dff745be1ed40a056a4b06c9ceb7fbbfda9afa26 0.0s
=> => naming to docker.io/zimbres/workerservice1 0.0s
@rainersigwald failing workflow:
https://github.com/bdovaz/dotnet-arm-test/actions/runs/3656031643/jobs/6178270233
In my case the error is different, but what is clear is that there are several errors/causes when using dotnet sdk 7 targeting arm.
Apart from giving the error, the process freezes and in order not to waste my free minutes, I have cancelled it.
#15 [build 7/7] RUN dotnet build "test.csproj" -c Release -o /app/build
#15 5.601 MSBuild version 17.4.0+18d5aef85 for .NET
#15 15.02 Determining projects to restore...
#15 18.62 All projects are up-to-date for restore.
#15 22.43 /usr/share/dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(2399,7): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [/src/test/test.csproj]
#15 22.43 /usr/share/dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(2399,7): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/src/test/test.csproj]
#15 22.43 /usr/share/dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(2399,7): error MSB4018: at InvokeStub_ResolveAssemblyReference.get_ResolvedFiles(Object, Object, IntPtr*) [/src/test/test.csproj]
#15 22.43 /usr/share/dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(2399,7): error MSB4018: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/test/test.csproj]
#15 22.44 /usr/share/dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(2399,7): error MSB4028: The "ResolveAssemblyReference" task's outputs could not be retrieved from the "ResolvedFiles" parameter. Object reference not set to an instance of an object. [/src/test/test.csproj]
Repo: https://github.com/bdovaz/dotnet-arm-test
Through this repository you can clearly see how an asp .net core project, simplified to the maximum (only with a few nuget references), fails.
hi, i'm facing the same issue trying docker buildx for arm64 on x86 with .net 7. with .net 6, it's working fine.
[build 12/15] RUN dotnet restore "MyCompany.ClientApi.Api/MyCompany.ClientAPI.Api.csproj":
33 | COPY ["MyCompany.ExternalApiDataAccess/MyCompany.ExternalApiDataAccess.csproj", "MyCompany.ExternalApiDataAccess/"] 34 | COPY ["NuGet.config", "NuGet.config"] 35 | >>> RUN dotnet restore "MyCompany.ClientApi.Api/MyCompany.ClientAPI.Api.csproj" 36 | COPY . . 37 | WORKDIR "/src/MyCompany.ClientApi.Api"
(I rely on translation tools. Sorry if there are any strange sentences.)
I have done some research on this issue to see what I can get.
In normal usage, you will encounter problems with buildx, but with Docker Desktop for Windows, you can simply reproduce the phenomenon by following these steps. (QEMU is installed in the Docker Desktop for Windows environment and can be emulated and executed.)
windows> docker run -it --rm mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim-arm64v8 bash
container# mkdir /work
container# cd /work
container# dotnet new console
container# dotnet build
/usr/share/dotnet/sdk/7.0.101/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. [/work/work.csproj]
Although we cannot build inside the container, we have brought externally built executables into the container for some experimentation.
In both cases, GetTargetFrameworkIdentifier/GetTargetFrameworkVersion yields normal results. Although the experiment was indirect, we do not believe there is a direct relationship between what appears in the error and the cause. I believe that upvote to QEMU issues such as dotnet/sdk#27190 would be closer to a solution.
Similar issue on Nuget restore for arm64 on x64:
`
`
This issue has been automatically marked as stale because we have not received a response in 14 days. It will be closed if no further activity occurs within another 14 days of this comment.
Responding to remove staleness.
Any progress on identifying the issue?
@rainersigwald @nkolev92 ping!
I have the same issue but its x32 architecture. Dockerfile: `FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim-arm32v7 AS base WORKDIR /app EXPOSE 80 EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim-arm32v7 AS build WORKDIR /src COPY ["Plant.Api/Plant.Api.csproj", "Plant.Api/"] COPY ["Plant.Core/Plant.Core.csproj", "Plant.Core/"] COPY ["Plant.Core.RabbitMQ/Plant.Core.RabbitMQ.csproj", "Plant.Core.RabbitMQ/"] COPY ["Plant.Core.TelegramBot/Plant.Core.TelegramBot.csproj", "Plant.Core.TelegramBot/"] COPY ["Plant.Core.DbContext/Plant.Core.DbContext.csproj", "Plant.Core.DbContext/"] COPY ["Plant.Core.MQTT/Plant.Core.MQTT.csproj", "Plant.Core.MQTT/"] COPY ["Plant.Camera/Plant.Camera.csproj", "Plant.Camera/"] RUN dotnet restore "Plant.Api/Plant.Api.csproj" --runtime linux-arm COPY . . WORKDIR "/src/Plant.Api" RUN dotnet build "Plant.Api.csproj" -c Release -r linux-arm -o /app/build
FROM build AS publish RUN dotnet publish "Plant.Api.csproj" -c Release -r linux-arm -o /app/publish
FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Plant.Api.dll"]`
Docker command:
docker buildx build --platform linux/arm/v7 \ -t private/repo:latest-armv7 \ -f $(Build.SourcesDirectory)/Plant.Api/Dockerfilearm $(Build.SourcesDirectory) \ --push \
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"Plant.Api/Plant.Api.csproj\" --runtime linux-arm" did not complete successfully: exit code: 1`
Similar issue on Nuget restore for arm64 on x64:
`#20 24.15 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1179,7): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/src/Brevity.Identity.csproj] #20 24.15
Please share repro steps with code for this one. No one else reported callstack with NuGet.targets
. This bug is about the error
#0 10.13 /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. [/src/src/EspUpdater/EspUpdater.csproj]
Your problem could be different one.
@erdembayar that call stack is a different bug, tracked by dotnet/runtime#78340. This bug is about the error
#0 10.13 /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. [/src/src/EspUpdater/EspUpdater.csproj]
That MSBuild property function is a pretty thin wrapper around a NuGet API, which is why we routed here.
@rainersigwald
I managed to get binlog (badBinlog.zip) and it looks like msbuild Evaluation
step is failed to bring Properties -> TargetFramework
, so I believe it's happening before any Nuget operation.
As you can see it doesn't have any Properties
section inside Evaluation
, compare to 2nd snapshot image from good restore which has that section.
Good restore binlog:
If you drilldown binlog in good restore then you'll see TargetFramework
property is set, but badBinlog
failing to evaluate this property since it's not set.
I have dotnet restore -v d
and dotnet restore --pp
log too, please let me know if you need anything from me.
I believe this issue is connected to https://github.com/dotnet/runtime/issues/78340
@aortiz-msft Based on my initial finding it looks like not NuGet issue, but I'll follow up it's the case.
Consistent repro steps:
With a private MSBuild that produces more exception information:
#0 11.47 18:16:40.724 1>/usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: The expression "[MSBuild]::GetTargetFrameworkVersion(net7.0, 2)" cannot be evaluated. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: ---> System.NullReferenceException: Object reference not set to an instance of an object. [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at InvokeStub_NuGetFramework.Parse(Object, Object, IntPtr*) [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: --- End of inner exception stack trace --- [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at Microsoft.Build.Evaluation.NuGetFrameworkWrapper.Parse(String tfm) in S:\msbuild\src\Build\Utilities\NuGetFrameworkWrapper.cs:line 59 [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at Microsoft.Build.Evaluation.NuGetFrameworkWrapper.GetTargetFrameworkVersion(String tfm, Int32 minVersionPartCount) in S:\msbuild\src\Build\Utilities\NuGetFrameworkWrapper.cs:line 69 [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at Microsoft.Build.Evaluation.IntrinsicFunctions.GetTargetFrameworkVersion(String tfm, Int32 versionPartCount) in S:\msbuild\src\Build\Evaluation\IntrinsicFunctions.cs:line 534 [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at Microsoft.Build.Evaluation.Expander`2.Function`1.TryExecuteWellKnownFunction(Object& returnVal, Object objectInstance, Object[] args) in S:\msbuild\src\Build\Evaluation\Expander.cs:line 4053 [/src/src/webapi/webapi.csproj]
#0 11.51 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(55,5): error MSB4184: at Microsoft.Build.Evaluation.Expander`2.Function`1.Execute(Object objectInstance, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation) in S:\msbuild\src\Build\Evaluation\Expander.cs:line 3481 [/src/src/webapi/webapi.csproj]
The string that we're passing to that method isn't null
, nor is the MethodInfo
we're trying to invoke.
Bafflingly I can call the exact same method the exact same way beforehand:
diff --git a/src/Build/Evaluation/Expander.cs b/src/Build/Evaluation/Expander.cs
index 88e5fea6c1..ea7a5b0b5a 100644
--- a/src/Build/Evaluation/Expander.cs
+++ b/src/Build/Evaluation/Expander.cs
@@ -3489,7 +3489,7 @@ namespace Microsoft.Build.Evaluation
return partiallyEvaluated;
}
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", partiallyEvaluated, ex.Message.Replace("\r\n", " "));
+ ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", partiallyEvaluated, ex.ToString().Replace("\r\n", " "));
}
if (!wellKnownFunctionSuccess)
diff --git a/src/Build/Utilities/NuGetFrameworkWrapper.cs b/src/Build/Utilities/NuGetFrameworkWrapper.cs
index 9d3546fcf3..077d2bb398 100644
--- a/src/Build/Utilities/NuGetFrameworkWrapper.cs
+++ b/src/Build/Utilities/NuGetFrameworkWrapper.cs
@@ -56,7 +56,14 @@ namespace Microsoft.Build.Evaluation
private object Parse(string tfm)
{
- return ParseMethod.Invoke(null, new object[] { tfm });
+ Console.WriteLine($"*** Parse({"net7.0"}) where ParseMethod = {ParseMethod} ***");
+ object firstReturn = ParseMethod.Invoke(null, new object[] { "net7.0" });
+ Console.WriteLine(firstReturn);
+
+ Console.WriteLine($"*** Parse({tfm}) where ParseMethod = {ParseMethod} ***");
+ object secondReturn = ParseMethod.Invoke(null, new object[] { tfm });
+ Console.WriteLine(secondReturn);
+ return secondReturn;
}
public string GetTargetFrameworkIdentifier(string tfm)
But I see the crash only on the "real" call:
#0 24.87 *** Parse(net7.0) where ParseMethod = NuGet.Frameworks.NuGetFramework Parse(System.String) ***
#0 24.89 net7.0
#0 24.89 *** Parse(net7.0) where ParseMethod = NuGet.Frameworks.NuGetFramework Parse(System.String) ***
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: The expression "[MSBuild]::GetTargetFrameworkIdentifier(net7.0)" cannot be evaluated. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: ---> System.NullReferenceException: Object reference not set to an instance of an object. [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at InvokeStub_NuGetFramework.Parse(Object, Object, IntPtr*) [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: --- End of inner exception stack trace --- [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at Microsoft.Build.Evaluation.NuGetFrameworkWrapper.Parse(String tfm) in S:\msbuild\src\Build\Utilities\NuGetFrameworkWrapper.cs:line 64 [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at Microsoft.Build.Evaluation.NuGetFrameworkWrapper.GetTargetFrameworkIdentifier(String tfm) in S:\msbuild\src\Build\Utilities\NuGetFrameworkWrapper.cs:line 71 [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at Microsoft.Build.Evaluation.IntrinsicFunctions.GetTargetFrameworkIdentifier(String tfm) in S:\msbuild\src\Build\Evaluation\IntrinsicFunctions.cs:line 529 [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at Microsoft.Build.Evaluation.Expander`2.Function`1.TryExecuteWellKnownFunction(Object& returnVal, Object objectInstance, Object[] args) in S:\msbuild\src\Build\Evaluation\Expander.cs:line 4040 [/src/src/webapi/webapi.csproj]
#0 25.38 /usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: at Microsoft.Build.Evaluation.Expander`2.Function`1.Execute(Object objectInstance, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation) in S:\msbuild\src\Build\Evaluation\Expander.cs:line 3481 [/src/src/webapi/webapi.csproj]
Given the nature of this issue (i.e. QEMU) and the variety of symptoms and callstacks that have been popping up as a result of it, I'm wondering whether the root cause is something in CoreCLR or even the compiler.
The stack trace Rainer provided doesn't show NuGet's code being executed. The only method that sounds like it might be NuGet is InvokeStub_NuGetFramework.Parse
, however, all of NuGet's namespaces start with NuGet.*
, not InvokeStub_
, so it seems like this is something that the reflection APIs generate internally. I agree it sounds like an issue the runtime team would be most expert at investigating.
In another context, @richlander pointed out https://gitlab.com/qemu-project/qemu/-/issues/249 which may be the underlying issue here.
Hey all,
As mentioned in the previous comments, all the signs point to this not being a NuGet issue, https://github.com/dotnet/runtime/issues/13648 and https://gitlab.com/qemu-project/qemu/-/issues/249.
The docs have been updated as well:
https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md#qemu https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md#qemu
Closing this as there's no action for NuGet.
Hey all,
As mentioned in the previous comments, all the signs point to this not being a NuGet issue, dotnet/runtime#13648 and https://gitlab.com/qemu-project/qemu/-/issues/249.
The docs have been updated as well:
https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md#qemu https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md#qemu
Closing this as there's no action for NuGet.
Thank you, I believe you're right, no action for NuGet.
Just want to clarify, if I'm already using docker buildx --platform
. We just need to switch the image version and the build process will switch from qemu
to native automatically?
Right. Give it a try. I'd love to hear your feedback.
In retrospect, and this is a failing of the post that I'll correct, the aspect you need .NET 8 for is you want to use the -a $TARGETARCH
pattern. The --platform=$BUILDPLATFORM
pattern works for any .NET version. It isn't even .NET specific. You can use that pattern with node, for example.
I have exactly the same issue and my pipeline is now dead, does anyone have a clue on how to fix that ??
I have exactly the same issue and my pipeline is now dead, does anyone have a clue on how to fix that ??
@matthieupetite (only) for the build stage, use .NET 8 nightly until 7.0.300 is out.
Check dotnet #4388.
Right. Give it a try. I'd love to hear your feedback.
In retrospect, and this is a failing of the post that I'll correct, the aspect you need .NET 8 for is you want to use the
-a $TARGETARCH
pattern. The--platform=$BUILDPLATFORM
pattern works for any .NET version. It isn't even .NET specific. You can use that pattern with node, for example.
My take: Your blog post was great insofar as it did provide a working solution, but I had to look into the pull request to figure out the exact change/feature in .NET 8. Looking forward for the same feature in .NET 7.0.300!
Glad to hear that the solution will work for you.
I didn't go into depth on what the exact change was (beyond enabling dotnet restore -a
). The exact change is quite mundane, but all the same required to make the scenario work.
Copied from post by @zimbres at https://github.com/dotnet/sdk/issues/28971:
When try to build arm64 containers using .Net7 results in a error on restore step.
Just create a new web api for example with .Net7 as target framework and try to build it with buildx. For amd64 build works just fine.
Docker Version
Docker Info