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

Support for reflection-invoking methods that take pointers by reference #10842

Open
Tracked by #44327 ...
MichalStrehovsky opened this issue Aug 6, 2018 · 8 comments
Open
Tracked by #44327 ...
Assignees
Labels
area-System.Reflection enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@MichalStrehovsky
Copy link
Member

dotnet/coreclr#17732 added support for reflection-invoking methods that return unmanaged pointers by reference (so e.g. ref void* Do()), but methods that get them by-reference as their parameters are still pretty broken (so e.g. void Do(ref void* x)).

For example:

using System;
using System.Reflection;

unsafe class Program
{
    public static void InvokeMe(out int* pointer)
    {
        pointer = (int*)0x12345;
    }

    static void Main(string[] args)
    {
        typeof(Program).GetMethod(nameof(InvokeMe)).Invoke(null, new object[] { null });
    }
}

Will crash the runtime with an ExecutionEngineException.

(Note this behavior is on parity with the desktop CLR, so it has quite likely been this broken for 17 years.)

@MichalStrehovsky
Copy link
Member Author

Cc @atsushikan @sergiy-k

@danmoseley
Copy link
Member

@MichalStrehovsky marked future. feel free to change.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 26, 2020
@GrabYourPitchforks
Copy link
Member

Expected behavior: Once this method returns, the object[] that's passed in contains a single element which is equivalent to having written System.Reflection.Pointer.Box((int*)12345, typeof(int)).

@GrabYourPitchforks GrabYourPitchforks added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Mar 26, 2020
@GrabYourPitchforks GrabYourPitchforks self-assigned this Mar 26, 2020
@GrabYourPitchforks GrabYourPitchforks modified the milestones: Future, 5.0 Mar 26, 2020
@steveharter
Copy link
Member

This does repro on 5.0 - ExecutionEngineException is thrown. Trying to ignore the exception with a try\catch results in Fatal error. Internal CLR error. (0x80131506)

@GrabYourPitchforks
Copy link
Member

@MichalStrehovsky Is this actually blocking a critical scenario? A workaround right now would be to define a delegate with an appropriate signature and to wrap that delegate around the target method.

What we want to avoid is spending a bunch of time addressing one-off issues in reflection that very few people will ever realistically run in to. We'd rather prioritize more impactful work items.

@MichalStrehovsky
Copy link
Member Author

@MichalStrehovsky Is this actually blocking a critical scenario?

Nope. If I remember correctly, I found this when we were adding System.Reflection.Pointer support into .NET Native (for NetStandard 2.0, since Pointer was new to NS2.0). I was writing tests and found out this doesn't work so I logged a bug. FWIW I think I made it work as expected in .NET Native.

@steveharter
Copy link
Member

See also #7430 which is similar but using a binder.

@steveharter
Copy link
Member

In v9, this now crashes with NullReferenceException in System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs.

@steveharter steveharter self-assigned this Jul 24, 2024
@steveharter steveharter modified the milestones: 9.0.0, 10.0.0 Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Reflection enhancement Product code improvement that does NOT require public API changes/additions
Projects
No open projects
Development

No branches or pull requests

8 participants