You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
While brainstorming ideas on how to workaround Marshal.GetFunctionPointerForDelegate() being unimplemented, I came up with the idea of using NativeCallableAttribute to give the method in question a C name, and then use a C stub method (exposed to C# as [DllImport("*")] method) to convert the name of the function into its pointer, which then can (hopefully) be passed safely into Win32.
Unfortunately, ILC is not emitting the entry-point thunk for the method in question. The symbol does not appear in the emitted object file, and as such the linker fails when I try to link in the name-to-pointer stub method. I can prove the method itself is compiled (both by running dumpbin /symbols on my object and by examining the verbose ILC output); the NativeCallableAttribute is just not honored. Weirdly, though, the NativeCallable functions in the CoreRT runtime are exported (and visible in dumpbin /symbols) -- good thing, too, or else my app would emit far more linker errors than it does.
If it helps, I am defining System.Runtime.InteropServices.NativeCallableAttribute in a separate assembly than System.Private.CoreLib, because this makes it easier for me to reference the type from my application code. Having reviewed ILC's handling of this type, I do not think that the assembly containing the attribute is considered, but I could be wrong.
I figured it out, actually. It seems that only the module containing the application's entry point and System.Private.CoreLib are scanned for methods marked with NativeCallableAttribute. @jkotas I can prepare a PR with a fix for this, if desired.
Activity
jkotas commentedon Jul 12, 2016
It should work.
I would set at breakpoint here to check why your custom methods are not getting picked up:
corert/src/ILCompiler.Compiler/src/Compiler/CompilationModuleGroup.cs
Line 97 in d85dc4f
wjk commentedon Jul 12, 2016
I figured it out, actually. It seems that only the module containing the application's entry point and
System.Private.CoreLibare scanned for methods marked withNativeCallableAttribute. @jkotas I can prepare a PR with a fix for this, if desired.wjk commentedon Jul 12, 2016
Closing as resolved; please see #1510 for the fix.