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

Hot Reload trimming errors debugging from vscode when targeting NativeAOT #21996

Open
trampster opened this issue Jan 16, 2025 · 1 comment
Open
Labels
bug If an issue is a bug or a pull request a bug fix hotrestart nativeaot
Milestone

Comments

@trampster
Copy link

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

Maui 9.0.21, vscode 1.95.3, .net maui vscode extension 1.6.16, dotnet 9.0.101, maui workload 9.0.0/9.0.100

Description

When trying to debug from the IDE with NativeAOT enabled the build fails with the following errors:

    /Users/hughesd/Work/hydra-src/apps/Xamarin-PTToX/src/Pttox.Forms/obj/Debug/net9.0-ios/ios-arm64/Microsoft.VisualStudio.HotReload.MobileTapInitializer/Microsoft.VisualStudio.HotReload.MobileTapInitializer.ModuleInitializerGenerator/HotReloadMobileTapInitializer.g.cs(48,33): error IL2026: Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
    /Users/hughesd/Work/hydra-src/apps/Xamarin-PTToX/src/Pttox.Forms/obj/Debug/net9.0-ios/ios-arm64/Microsoft.VisualStudio.HotReload.MobileTapInitializer/Microsoft.VisualStudio.HotReload.MobileTapInitializer.ModuleInitializerGenerator/HotReloadMobileTapInitializer.g.cs(55,33): error IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String, BindingFlags)'. The return value of method 'System.Reflection.Assembly.GetType(String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Steps to Reproduce

  1. Create a maui project targetting iOS dotnet new maui
  2. Modify the .csproj to target NativeAOT
      <IsAotCompatible>true</IsAotCompatible>
      <PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</PublishAot>
  1. Attach and iOS device and select it in vscode. Try to debug using Ctrl-F5
    -> hot reload trimming errors occur as per description above

Did you find any workaround?

No

Build logs

No response

@rolfbjarne
Copy link
Member

It looks like the code we inject when using Hot Restart isn't trimmer safe, so when the trimmer warnings are automatically enabled (which happens when NativeAOT is enabled), the build emits trimmer warnings (and I also assume you're building with warnings-as-errors).

Conditionally enabling NativeAOT might do as a workaround:

<PropertyGroup Condition="'$(IsHotRestartBuild)' != 'true'">
    <IsAotCompatible>true</IsAotCompatible>
    <PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</PublishAot>
</PropertyGroup>

@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Jan 17, 2025
@rolfbjarne rolfbjarne added this to the .NET 10 milestone Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix hotrestart nativeaot
Projects
None yet
Development

No branches or pull requests

2 participants