Why does core_create_delegate appear to only support on-disk assemblies? Can this be changed? #99203
-
Hey everyone. My scenario I then attempt to call coreclr_create_delegate once again in order to reference the methods in the loaded ScriptAssembly. A bunch of searching suggests this is a 'file not found' code. So I decided to go look around the source of CLRCore, hoping to understand enough to confirm what was happening. So I am loading Coreclr.dll and getting a reference to coreclr_create_delegate via a GetProcAddress method. This would appear to get me to runtime/src/coreclr/dlls/mscoree/exports.cpp Line 428 in 37445d4 From here I need to find an implementation of CreateDelegate runtime/src/coreclr/vm/corhost.cpp Line 672 in 37445d4 With reference to the following code... If I'm reading the code correctly, it would seem that there is an assumption here, that the assembly being targetted must be on disk and not already in memory. So a few questions... Am I remotely in the right location? ie. have I correctly traced the path of the code? Am I correct that the code can currently only operate against assemblies which are on disk (ie within dll files)? Is there any reason why this should not be changed? Any tips? Is there some other way around my predicament. Many thanks for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Yes, it is the correct location.
I do not think you are correct. This |
Beta Was this translation helpful? Give feedback.
-
Worked like a charm. Thankyou so very much @jkotas. Not only an accurate answer, but with good background info also. |
Beta Was this translation helpful? Give feedback.
coreclr_create_delegate
expects the assembly to be loaded in the default load context.Assembly.Load(byte[])
loads the assembly into its own load context. It explains whycoreclr_create_delegate
does not see it.Try loading the in-memory assembly using
AssemblyLoadContext.LoadFromStream
method instead. It is going to load it explicitly into the default load context and make it visible tocoreclr_create_delegate
.