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

[NativeAOT] AccessViolationException when making reflection calls over DIMs #109893

Closed
eiriktsarpalis opened this issue Nov 16, 2024 · 2 comments · Fixed by #109917
Closed

[NativeAOT] AccessViolationException when making reflection calls over DIMs #109893

eiriktsarpalis opened this issue Nov 16, 2024 · 2 comments · Fixed by #109917
Assignees
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Nov 16, 2024

Description

I encountered this regression while migrating a library of mine to .NET 9.

Reproduction Steps

Compile and run the following console app as a NAOT application

IType type = new Type<object>();
type.Accept(new MyVisitor());

class Type<T> : IType<T>;

class MyVisitor : IVisitor
{
    public object? Visit<T>(IType<T> _) => typeof(T);
}

//--------------------------------

interface IType
{
    object? Accept(IVisitor visitor);
}

interface IType<T> : IType
{
    object? IType.Accept(IVisitor visitor) => visitor.Visit(this);
}

interface IVisitor
{
    object? Visit<T>(IType<T> type);
}

Expected behavior

Should execute without incident.

Actual behavior

Throws the following exception:

Process terminated. Access Violation: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The application will be terminated since this platform does not support throwing an AccessViolationException.
   at System.RuntimeExceptionHelpers.FailFast(String, Exception, String, RhFailFastReason, IntPtr, IntPtr) + 0x200
   at System.RuntimeExceptionHelpers.GetRuntimeException(ExceptionIDs) + 0x148
   at System.Runtime.EH.GetClasslibException(ExceptionIDs, IntPtr) + 0x48
   at IType`1.IType.Accept(IVisitor) + 0x18
   at Program.<Main>$(String[] args) + 0x40

Regression?

This is a regression from .NET 8.

Known Workarounds

No response

Configuration

.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.3068a692
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-arm64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100\

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 16, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

eiriktsarpalis added a commit to eiriktsarpalis/PolyType that referenced this issue Nov 16, 2024
@agocke agocke added this to the 9.0.x milestone Nov 17, 2024
@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Nov 17, 2024
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Nov 18, 2024
Regression test from dotnet#109893. This was fixed in dotnet#108235 but that one only has testcases that involve `IDynamicInterfaceCastable`.
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Nov 18, 2024
@MichalStrehovsky
Copy link
Member

So looks like this is already fixed in .NET 10 - #108235 happens to also fix this because it touched the logic just enough. The problem was with us not marking the interface as used.

I'll request a backport.

I also made a pull request that adds this testcase since all tests for #108235 involved IDynamicInterfaceCastable.

MichalStrehovsky added a commit that referenced this issue Nov 18, 2024
Regression test from #109893. This was fixed in #108235 but that one only has testcases that involve `IDynamicInterfaceCastable`.
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this issue Dec 10, 2024
Regression test from dotnet#109893. This was fixed in dotnet#108235 but that one only has testcases that involve `IDynamicInterfaceCastable`.
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants