Skip to content

Avoid linker errors when compiling for AOT. #21806

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henric-root
Copy link

Using Marshal.SizeOf(typeof(T)) or Enum.GetValues(typeof(T)) can cause AOT builds to fail when including the Google.Protobuf NuGet package and using the tools from a recent enough .NET SDK (9.0.300 or possibly earlier).

Set <TrimmerSingleWarn>false</TrimmerSingleWarn> and <TreatWarningsAsErrors>True</TreatWarningsAsErrors> to see something like this:

/_/csharp/src/Google.Protobuf/Collections/RepeatedField.cs(714): AOT analysis error IL3050: Google.Protobuf.Collections.RepeatedField`1.TryGetArrayAsSpanPinnedUnsafe(FieldCodec`1<T>,Span`1<Byte>&,GCHandle&): Using member 'System.Runtime.InteropServices.Marshal.SizeOf(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Marshalling code for the object might not be available. Use the SizeOf<T> overload instead. [/src/xxxx/xxxx.csproj]
/root/.nuget/packages/microsoft.dotnet.ilcompiler/9.0.5/build/Microsoft.NETCore.Native.targets(317,5): error MSB3073: The command ""/root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.5/tools/ilc" @"obj/Release/net9.0/linux-x64/native/RootApp.HubServer.ilc.rsp"" exited with code -1. [/src/xxxx/xxxx.csproj]

@henric-root henric-root requested a review from a team as a code owner May 17, 2025 01:15
@henric-root henric-root requested review from jskeet and removed request for a team May 17, 2025 01:15
Copy link

google-cla bot commented May 17, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jskeet jskeet removed their request for review May 17, 2025 06:31
Using Marshal.SizeOf(typeof(T)) or Enum.GetValues(typeof(T)) can cause
AOT builds to fail when including the Google.Protobuf NuGet package and
using the tools from a recent enough .NET SDK (9.0.300 or possibly
earlier).

Set <TrimmerSingleWarn>false</TrimmerSingleWarn> and
<TreatWarningsAsErrors>True</TreatWarningsAsErrors> to see something like
this:

/_/csharp/src/Google.Protobuf/Collections/RepeatedField.cs(714): AOT analysis error IL3050: Google.Protobuf.Collections.RepeatedField`1.TryGetArrayAsSpanPinnedUnsafe(FieldCodec`1<T>,Span`1<Byte>&,GCHandle&): Using member 'System.Runtime.InteropServices.Marshal.SizeOf(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Marshalling code for the object might not be available. Use the SizeOf<T> overload instead. [/src/xxxx/xxxx.csproj]
/root/.nuget/packages/microsoft.dotnet.ilcompiler/9.0.5/build/Microsoft.NETCore.Native.targets(317,5): error MSB3073: The command ""/root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.5/tools/ilc" @"obj/Release/net9.0/linux-x64/native/RootApp.HubServer.ilc.rsp"" exited with code -1. [/src/xxxx/xxxx.csproj]
@henric-root henric-root force-pushed the aot-link-errors-with-sdk-9 branch from 7af7fa0 to 0549c8d Compare August 5, 2025 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants