Load Assembly into AppDomain from memory?
So, here's the problem: I have a program that compiles source code into a System.Reflection.Assembly object, and I want to run that on an AppDomain. All of the methods and overloads for loading that Assembly into said AppDomain throw an exception when I try to load the Assembly. Does it absolutely have to be a file, or is there another way to load an assembly into an appdomain? If it'll be necessary, how would you get a byte array from the Assembly object? Any help would be greatly appreciated, reflection has got me bleeding from the eyes here. @_@
You'll need to load it from a file.
Damn it. But isn't there a way to serialize it to a byte array from an object?
like.... object a = MyAssembly, and then convert the object into a byte array?
I don't know how to do this, but I read somewhere that it's possible. :/
What I'm doing is compiling an assembly in memory, so a file version of it never exists, and I'm trying to pass that assembly object to an AppDomain, but I guess there's no realistic way to get a byte array from it in memory or to simply pass it from memory to the AppDomain. /derp
I could only find a few threads about this on Google and they were saying to use IO.File.ReadAllBytes but in your case, you can't.
If you use the AssemblyBuilder class though, you can Save it.
I'm not looking to save it to a file, as I can just compile it to a file via CodeDom, what I'm doing is generating Assemblies in memory, and I want to load it into an AppDomain but there's no way to do it without using a file. I think what I'll have to do is compile to files, load all assemblies, and delete the files once they've loaded into memory. :/ A lot more than would have to be done if you could simply load assemblies from memory, fucking microsoft and our damned love/hate relationship.