Skip to content

System.NotImplementedException in ComWrappers.TryGetOrCreateObjectForComInstanceInternal on NativeAOT #89713

@ahmed605

Description

@ahmed605

Description

I get System.NotImplementedException in ComWrappers.TryGetOrCreateObjectForComInstanceInternal when COM Aggregation is used when using ComWrappers.GetOrRegisterObjectForComInstance like in case of WinRT class inheriting.

Reproduction Steps

  1. Clone https://github.com/ahmed605/NativeAOTComWrappersAggregationRepro
  2. Open a VS Developer Command Prompt
  3. cd to NativeAOTComWrappersAggregationRepro
  4. Publish with NativeAOT:
msbuild NativeAOTComWrappersAggregationRepro.csproj -t:restore,publish /p:Configuration=Release /p:Platform=x64 /p:RuntimeIdentifier=win-x64 /p:TargetFramework=net8.0-windows10.0.22000.0
  1. Run the published .exe
  2. Attach a debugger
  3. Press any key to continue execution

Expected behavior

The app prints "Hello!" to the console.

Actual behavior

Crash with System.NotImplementedException in ComWrappers.TryGetOrCreateObjectForComInstanceInternal

image

And this is printed into the console:

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
   at System.Runtime.InteropServices.ComWrappers.TryGetOrCreateObjectForComInstanceInternal(IntPtr, IntPtr, CreateObjectFlags, Object, Object&) + 0x554
   at System.Runtime.InteropServices.ComWrappers.GetOrRegisterObjectForComInstance(IntPtr, CreateObjectFlags, Object, IntPtr) + 0x30
   at WinRT.ComWrappersHelper.Init(Boolean, Object, IntPtr, IntPtr, IObjectReference&) + 0x151
   at TestComponent.Class..ctor() + 0x72
   at NativeAOTComWrappersAggregationRepro.Program.Main(String[] args) + 0x29
   at NativeAOTComWrappersAggregationRepro!<BaseAddress>+0x2735c4

Stacktrace:

NativeAOTComWrappersAggregationRepro.exe!S_P_CoreLib_System_Runtime_InteropServices_ComWrappers__TryGetOrCreateObjectForComInstanceInternal() Line 726
NativeAOTComWrappersAggregationRepro.exe!S_P_CoreLib_System_Runtime_InteropServices_ComWrappers__GetOrRegisterObjectForComInstance_0() Line 648
NativeAOTComWrappersAggregationRepro.exe!WinRT_Runtime_WinRT_ComWrappersHelper__Init()
NativeAOTComWrappersAggregationRepro.exe!TestComponent_Projection_TestComponent_Class___ctor() Line 108
NativeAOTComWrappersAggregationRepro.exe!NativeAOTComWrappersAggregationRepro_NativeAOTComWrappersAggregationRepro_Program__Main() Line 15
NativeAOTComWrappersAggregationRepro.exe!NativeAOTComWrappersAggregationRepro__Module___StartupCodeMain()
NativeAOTComWrappersAggregationRepro.exe!wmain(int argc, wchar_t * * argv) Line 218
[Inline Frame] NativeAOTComWrappersAggregationRepro.exe!invoke_main() Line 90
NativeAOTComWrappersAggregationRepro.exe!__scrt_common_main_seh() Line 288
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8.0.100 Preview 6 SDK

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions