Skip to content

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

Open
@trampster

Description

@trampster

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIf an issue is a bug or a pull request a bug fixhotrestartnativeaot

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions