NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 253 forks source link

dotnet restore fails in Arm-based container on an x64 host machine #12227

Closed mthalman closed 1 year ago

mthalman commented 1 year ago

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.

PS C:\Users\Marcio\OneDrive\Documents\VSCode\asp.net\EspUpdater> docker buildx build --platform linux/arm64 -t zimbres/espupdater -f .\src\EspUpdater\Dockerfile --push . --no-cache
[+] Building 66.2s (12/17)
 => [internal] load .dockerignore                                                                                                                                                                                          0.1s
 => => transferring context: 382B                                                                                                                                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                       0.1s
 => => transferring dockerfile: 622B                                                                                                                                                                                       0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:7.0                                                                                                                                                          2.3s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:7.0                                                                                                                                                       2.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:7.0@sha256:39069a126f2e3dd8f3aa72a21688d4de13ba23b051a8c5856be1460f8165c422                                                                                             52.0s
 => => resolve mcr.microsoft.com/dotnet/sdk:7.0@sha256:39069a126f2e3dd8f3aa72a21688d4de13ba23b051a8c5856be1460f8165c422                                                                                                    0.0s
 => => sha256:d508dcfcdd2e1834750cbcc43a9e0f44625d7cdbb349be5342f069a0a26a9d20 13.42MB / 13.42MB                                                                                                                           8.7s
 => => sha256:edd0ccac63956573208572413f089dcc51a922baced37a1c3588d55701aab5c3 150.47MB / 150.47MB                                                                                                                        38.8s
 => => sha256:62558e356c6cd900192712f446fefcd8029f9f54b12c87b4b342a392d2e9e9ed 25.39MB / 25.39MB                                                                                                                          11.1s
 => => extracting sha256:62558e356c6cd900192712f446fefcd8029f9f54b12c87b4b342a392d2e9e9ed                                                                                                                                  1.7s
 => => extracting sha256:edd0ccac63956573208572413f089dcc51a922baced37a1c3588d55701aab5c3                                                                                                                                  3.2s
 => => extracting sha256:d508dcfcdd2e1834750cbcc43a9e0f44625d7cdbb349be5342f069a0a26a9d20                                                                                                                                  0.3s
 => [internal] load build context                                                                                                                                                                                          0.1s
 => => transferring context: 6.72kB                                                                                                                                                                                        0.0s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:7.0@sha256:cc60f5590843f067871d72ffc99d3065f8556624d45465948166b11a08714ddc                                                                                           22.7s
 => => resolve mcr.microsoft.com/dotnet/aspnet:7.0@sha256:cc60f5590843f067871d72ffc99d3065f8556624d45465948166b11a08714ddc                                                                                                 0.0s
 => => sha256:9855365906865f18e48e4132950bb1f031a37afd9487af259eb8618313aaa672 9.80MB / 9.80MB                                                                                                                             6.2s
 => => sha256:e48426b90b5fe27894046a6b96e67e208ec25e2768a1c5bf76d233fa1ec1e7d6 155B / 155B                                                                                                                                 0.3s
 => => sha256:eafd3893bf918fb60399acce35d47fc92934372f519a0dc8ea56b7ae552a1524 30.71MB / 30.71MB                                                                                                                          19.1s
 => => sha256:dd6189d6fc13cb03db0f4a3d9659b6b6044fd5858019d659001eaf8367584d67 30.06MB / 30.06MB                                                                                                                          19.4s
 => => sha256:8487b5d2f3511cc5ae78d3f730d7f7e8f06466f6281464355fd6a464c95cab36 14.92MB / 14.92MB                                                                                                                           9.2s
 => => extracting sha256:dd6189d6fc13cb03db0f4a3d9659b6b6044fd5858019d659001eaf8367584d67                                                                                                                                  1.5s
 => => extracting sha256:8487b5d2f3511cc5ae78d3f730d7f7e8f06466f6281464355fd6a464c95cab36                                                                                                                                  0.4s
 => => extracting sha256:eafd3893bf918fb60399acce35d47fc92934372f519a0dc8ea56b7ae552a1524                                                                                                                                  0.8s
 => => extracting sha256:e48426b90b5fe27894046a6b96e67e208ec25e2768a1c5bf76d233fa1ec1e7d6                                                                                                                                  0.0s
 => => extracting sha256:9855365906865f18e48e4132950bb1f031a37afd9487af259eb8618313aaa672                                                                                                                                  0.3s
 => [base 2/2] WORKDIR /app                                                                                                                                                                                                0.7s
 => [final 1/2] WORKDIR /app                                                                                                                                                                                               0.1s
 => [build 2/7] WORKDIR /src                                                                                                                                                                                               1.4s
 => [build 3/7] COPY [src/EspUpdater/EspUpdater.csproj, src/EspUpdater/]                                                                                                                                                   0.0s
 => ERROR [build 4/7] RUN dotnet restore "src/EspUpdater/EspUpdater.csproj"                                                                                                                                               10.5s
------
 > [build 4/7] RUN dotnet restore "src/EspUpdater/EspUpdater.csproj":
#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:8
--------------------
   6 |     WORKDIR /src
   7 |     COPY ["src/EspUpdater/EspUpdater.csproj", "src/EspUpdater/"]
   8 | >>> RUN dotnet restore "src/EspUpdater/EspUpdater.csproj"
   9 |     COPY . .
  10 |     WORKDIR "/src/src/EspUpdater"
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"src/EspUpdater/EspUpdater.csproj\"" did not complete successfully: exit code: 1

Docker Version

PS C:\Users\Marcio\OneDrive\Documents\VSCode\asp.net\EspUpdater> docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.20
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        9fdeb9c
 Built:             Tue Oct 18 18:28:44 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.13.1 (90346)
 Engine:
  Version:          20.10.20
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       03df974
  Built:            Tue Oct 18 18:18:35 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker Info

PS C:\Users\Marcio\OneDrive\Documents\VSCode\asp.net\EspUpdater> docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.5.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.3)
  extension: Manages Docker extensions (Docker Inc., v0.2.13)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.21.0)

Server:
 Containers: 18
  Running: 4
  Paused: 0
  Stopped: 14
 Images: 40
 Server Version: 20.10.20
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.102.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.6GiB
 Name: docker-desktop
 ID: BGP4:KFNX:A6XV:MDJT:AKET:PD7L:O7YG:6SHF:KNRB:EFFD:PD3W:6OC2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
mthalman commented 1 year ago

See the original issue at https://github.com/dotnet/sdk/issues/28971 for more details.

ghost commented 1 year ago

Issue is missing Type label, remember to add a Type label

donnie-msft commented 1 year ago

@BenVillalobos @rainersigwald Did you try reproing with a private MSBuild to get the whole stack?

donnie-msft commented 1 year ago

@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!

mthalman commented 1 year ago

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.

dotnetapp.zip

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.

zimbres commented 1 year ago

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"]
quentez commented 1 year ago

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

benvillalobos commented 1 year ago

@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]
zimbres commented 1 year ago

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"]
benvillalobos commented 1 year ago

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]
erdembayar commented 1 year ago

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>
zimbres commented 1 year ago

You need to be on .sln folder:

image

docker buildx build --platform linux/arm64 -t zimbres/espupdater -f MyApp\Dockerfile --push . --no-cache

erdembayar commented 1 year ago

You need to be on .sln folder:

image

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.

erdembayar commented 1 year ago

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

HazyFish commented 1 year ago

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

erdembayar commented 1 year ago

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.

erdembayar commented 1 year ago

@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

rainersigwald commented 1 year ago

@erdembayar how did you determine that?

erdembayar commented 1 year ago

@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. image

rainersigwald commented 1 year ago

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

nkolev92 commented 1 year ago

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

deannagarcia commented 1 year ago

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.

bdovaz commented 1 year ago

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

rainersigwald commented 1 year ago

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
bdovaz commented 1 year ago

@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]

Raw logs: https://pipelines.actions.githubusercontent.com/serviceHosts/1b01894f-785a-4591-83bc-5015b1012bd5/_apis/pipelines/1/runs/4/signedlogcontent/2?urlExpires=2022-12-09T09%3A44%3A55.5049356Z&urlSigningMethod=HMACV1&urlSignature=Qy%2FDerpbIRQnu3CkfEq3%2FL%2BByG19TuwZIXEEosJ7dkE%3D

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.

brignolij commented 1 year ago

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":

0 14.60 /usr/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4184: The expression "[MSBuild]::GetTargetFrameworkIdentifier(net7.0)" cannot be evaluated. Exception has been thrown by the target of an invocation. [/src/MyCompany.ClientApi.Api/MyCompany.ClientAPI.Api.csproj]


Dockerfile:35

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"

toras9000 commented 1 year ago

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

fvoncina commented 1 year ago

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 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1179,7): error MSB4018: at InvokeStub_MSBuild.get_TargetOutputs(Object, Object, IntPtr*) [/src/Brevity.Identity.csproj]

20 24.15 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1179,7): error MSB4018: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/Brevity.Identity.csproj]

20 24.15 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1179,7): error MSB4028: The "MSBuild" task's outputs could not be retrieved from the "TargetOutputs" parameter. Object reference not set to an instance of an object. [/src/Brevity.Identity.csproj]

20 24.18 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1235,7): error MSB4018: The "MSBuild" task failed unexpectedly. [/src/Brevity.Identity.csproj]

20 24.18 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1235,7): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/src/Brevity.Identity.csproj]

20 24.18 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1235,7): error MSB4018: at InvokeStub_MSBuild.get_TargetOutputs(Object, Object, IntPtr*) [/src/Brevity.Identity.csproj]

20 24.18 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1235,7): error MSB4018: at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) [/src/Brevity.Identity.csproj]

20 24.19 /usr/share/dotnet/sdk/7.0.101/NuGet.targets(1235,7): error MSB4028: The "MSBuild" task's outputs could not be retrieved from the "TargetOutputs" parameter. Object reference not set to an instance of an object. [/src/Brevity.Identity.csproj]

`

ghost commented 1 year ago

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.

mthalman commented 1 year ago

Responding to remove staleness.

Any progress on identifying the issue?

bdovaz commented 1 year ago

@rainersigwald @nkolev92 ping!

lata22 commented 1 year ago

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: `Dockerfilearm:17

15 | COPY ["Plant.Core.MQTT/Plant.Core.MQTT.csproj", "Plant.Core.MQTT/"] 16 | COPY ["Plant.Camera/Plant.Camera.csproj", "Plant.Camera/"] 17 | >>> RUN dotnet restore "Plant.Api/Plant.Api.csproj" --runtime linux-arm 18 | COPY . . 19 | WORKDIR "/src/Plant.Api"

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`

erdembayar commented 1 year ago

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 commented 1 year ago

@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. image

Good restore binlog: image 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. image

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.

erdembayar commented 1 year ago

Consistent repro steps:

  1. https://github.com/erdembayar/12227_docker_crash.git
  2. docker buildx build --platform linux/arm64 -t zimbres/workerservice1 -f .\webapi\Dockerfile . --no-cache
rainersigwald commented 1 year ago

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.

rainersigwald commented 1 year ago

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]
mthalman commented 1 year ago

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.

zivkan commented 1 year ago

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.

rainersigwald commented 1 year ago

In another context, @richlander pointed out https://gitlab.com/qemu-project/qemu/-/issues/249 which may be the underlying issue here.

nkolev92 commented 1 year ago

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.

erdembayar commented 1 year ago

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.

richlander commented 1 year ago

FYI: FYI: https://github.com/dotnet/dotnet-docker/issues/4388#issuecomment-1470996533

richlander commented 1 year ago

FYI: https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/

HazyFish commented 1 year ago

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?

richlander commented 1 year ago

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.

matthieupetite commented 1 year ago

I have exactly the same issue and my pipeline is now dead, does anyone have a clue on how to fix that ??

goncalo-oliveira commented 1 year ago

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.

joergjo commented 1 year ago

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!

richlander commented 1 year ago

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.