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

IL3000 error in MsQuicApi..cctor when publishing AOT #109958

Open
euju-ms opened this issue Nov 14, 2024 · 10 comments
Open

IL3000 error in MsQuicApi..cctor when publishing AOT #109958

euju-ms opened this issue Nov 14, 2024 · 10 comments
Assignees
Milestone

Comments

@euju-ms
Copy link

euju-ms commented Nov 14, 2024

Describe the bug

When publishing an app that uses HttpClient, it results in IL3000.

System.Net.Quic.MsQuicApi..cctor(): 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

To Reproduce

Here's a repo that contains the minimal repro console app: https://github.com/euju-ms/MsQuicApiError

  1. Download the source code then open MsQuicApiError.sln from VisualStudio
  2. Publish the project MsQuicApiError using Properties\PublishProfiles\FolderProflie.pubxml, then observe the error.

Exceptions (if any)

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.c6f19616
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.23786
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.12.35506.116
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  6.0.136 [C:\Program Files\dotnet\sdk]
  6.0.321 [C:\Program Files\dotnet\sdk]
  6.0.428 [C:\Program Files\dotnet\sdk]
  7.0.120 [C:\Program Files\dotnet\sdk]
  7.0.410 [C:\Program Files\dotnet\sdk]
  8.0.111 [C:\Program Files\dotnet\sdk]
  8.0.307 [C:\Program Files\dotnet\sdk]
  9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  c:\Users\euju\RiderProjects\OSClient\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its versionz
Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.12.0
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Nov 14, 2024
@euju-ms euju-ms changed the title IL3000 on MsQuicApi..cctor when publishing AOT IL3000 error in MsQuicApi..cctor when publishing AOT Nov 14, 2024
@euju-ms
Copy link
Author

euju-ms commented Nov 14, 2024

By the way, if I change the TargetPlatform to net9.0 then publish, then the publish succeeds.

@MIRIMIRIM
Copy link

I also experienced the same warning, but I didn't use HttpClient. And dotnet version are 8.0.404 and 9.0.100, TargetFramework is also net8.0

@dozer75
Copy link

dozer75 commented Nov 15, 2024

I did get the same as well when I tried to include HttpClient and set it up in a project using AOT... Isn't HttpClient AOT compatible because of Quic dependency in .NET 8? I can verify that it does work in .NET 9, but in my current assignment we're not supposed to use non LTS .NET versions...

The message is not that intuitive either so the AOT build warnings could certainly get some improvements...

@acraven
Copy link

acraven commented Nov 16, 2024

We have been experiencing this when building an AOT console app (to deploy as an AWS lambda function) since the release of 8.0.404. I don't recall us using HttpClient in our builds that were failing (due to MSBuildShowWarningsAsErrors), but we did produce a min-repro which was almost identical to the OP's. We have not seen the problem with 9.0.

We are faced with the following choices:
a) Pin the SDK we build on to 8.0.403 and hope this is resolved before we need an 8.x.x security patch.
b) Upgrade to 9.0 and use an STS build until the next LTS build is released.
c) Ignore the IL3000 warning and hope this does not produce a runtime error.

We've chosen option a) for the time being.

@ByronAP
Copy link

ByronAP commented Nov 18, 2024

"OS Version: 10.0.23786" isn't MS QUIC only supported on Windows 11

@Evangelink
Copy link
Member

We have a similar issue on MSTest, one of our acceptance test is starting to fail with the exact same error. Targeting net9.0 is also not triggering an issue.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 19, 2024
@MichalStrehovsky MichalStrehovsky transferred this issue from dotnet/sdk Nov 19, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Nov 19, 2024

This is a bug in the warning suppression:

#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
// Windows ships msquic in the assembly directory next to System.Net.Quic, so load that.
// For single-file deployments, the assembly location is an empty string so we fall back
// to AppContext.BaseDirectory which is the directory containing the single-file executable.
string path = typeof(MsQuicApi).Assembly.Location is string assemblyLocation && !string.IsNullOrEmpty(assemblyLocation)
? System.IO.Path.GetDirectoryName(assemblyLocation)!
: AppContext.BaseDirectory;
#pragma warning restore IL3000

This suppresses the warning for the Roslyn analyzer when building the repo, but not in the output IL that the AOT compiler looks at.

This needs to use the UnconditionalSuppressMessageAttribute to do suppression (and drop the pragma suppression).

As for workarounds, the only thing that can be done is suppressing the warning with NoWarn and then remembering to remove the suppression once this is fixed.

@MichalStrehovsky
Copy link
Member

Out of curiosity, why do we need to do this? I would expect DllImportSearchPath.AssemblyDirectory to have this behavior in a single-file-safe manner. Also, why do we only need this in .NET 8? (It took a while finding this place because neither main nor release/9.0 seem to have this modified probing logic)

@MichalStrehovsky MichalStrehovsky added this to the 8.0.x milestone Nov 19, 2024
@MichalStrehovsky MichalStrehovsky removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 19, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Nov 19, 2024
@rzikm rzikm self-assigned this Nov 19, 2024
@rzikm
Copy link
Member

rzikm commented Nov 19, 2024

We are working on a fix, in the meantime, suppressing the warning or pinning to a previous SDK version (e.g. via global.json) is probably the best available workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants