-
Notifications
You must be signed in to change notification settings - Fork 509
Assembly Load(byte[]) with native compiled exe/dll #6958
Comments
It does not matter whether the assembly is bytes in memory or file on disk. The solution is same for both. |
@jkotas, @MichalStrehovsky English isn't my first language so apologies for that, I try to rephrase my goal: |
Once managed code is compiled to native code, the resulting executable file is native. The file is no different from a native executable generated by e.g. C or C++. You cannot load it back into a CoreRT process and expect to be able to do things with it. It will not work, same way it would not work to e.g. |
@MichalStrehovsky Thanks for clearing that up. Could you please give an example on how to execute a native assembly loaded from bytes? I appreciate it. |
It's not possible on Windows; you have to write the buffer to a file on disk and load from there. I don't know about Linux/macOS. |
@MichalStrehovsky, @jkotas : So there is no equivalent to MemoryModule (1000+ stars https://github.com/fancycode/MemoryModule) in CoreRT? Maybe we see it in future? |
You can build MemoryModule as a library and p/invoke into it from C#. We are not planning to add similar functionality to CoreRT proper. Bypassing the operating system's module loader means that the operating system is not aware of the module. Lots of things will work, but there will be things that don't work as expected. We don't want to take on that support burden. |
@MichalStrehovsky: Fair enough. So after all there is no way to load a native assembly from bytes in .NET Core. Thanks and have a great day! |
I am really excited and fascinated by CoreRT!
Porting one of my existing projects I struggle with this code:
My main program/exe (c# compiled to native code) wants to load my library "native_helper.dll" bytes (also c# compiled to native code). It throws this error:
In System.Private.CoreLib.dll it checks for "AppDomain.CheckLoadByteArraySupported();" and I guess that's where it crashes.
I searched through the samples and tried serveral options in .csproj. I ended up with those:
How can I load assembly bytes into my program like in .NET Framework (code above)? Is this even possible after compiling it into native code? Thanks guys!
The text was updated successfully, but these errors were encountered: