Skip to content

Assembly.GetCallingAssembly() needs IL2026-like warning for Native AOT (and self contained) builds #94200

Description

@HighPerfDotNet

Description

I am trying to get Native AOT build working with NET 8 RC2 and run into the following situation:

Assembly.GetCallingAssembly() throws System.PlatformNotSupportedException: Operation is not supported on this platform.

Once I tracked it down to this it became apparent that this is due to self-contained file not having calling assembly per se, which is fine, but it would have been VERY helpful if compiler/linker produced IL2026-like warning that this usage will fail, right now there is none, so that took extra time to locate what was going on. IL2026 warnings are very helpful pointing out likely issues for Native AOT builds and this instance deserves to be added to the list.

It's possible there are other similar exceptions that would deserve similar warning for Native AOT or even just self-contained builds.

Reproduction Steps

// Native AOT build -

Assembly.GetCallingAssembly();

Expected behavior

I expected to see IL2026-like warning from compiler, maybe even elevated to error that needs to be actively supressed if user desires so.

Actual behavior

No warning during compile/link time.

Regression?

No

Known Workarounds

No response

Configuration

Windows 11 Pro on Intel x64
Visual Studio 2022 17.8 Preview 5

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions