![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Hello, Graven! You wrote on 5 Aug 2006 03:38:09 -0700: G> Recently I've tried to load an assembly from a byte stream using the G> method Load(Byte[] rawAssembly). The test assembly was a single-module G> assembly that referenced nothing but mscorlib. I've renamed the G> assembly to someting messy, and then got its contents to a byte array G> using File.ReadAllBytes. G> The actual problem comes here. G> When I'm using Assembly.Load(byte[] rawAssembly), it loads ok. But when G> the same byte array is used with AppDomain.Load(byte[] rawAssembly), G> I'm getting FileIOException with the message "Assembly [the original G> name of my assembly] was not found". What surprised me the most is the G> fact that both these methods internally use Assembly.nLoadImage G> (figured it out with Reflector). G> Anyone has an explanation for this weird behavior? I couldn't repeat your situation with mere loading. This code works fine: string appBase; object obj; Assembly loadedAssembly; MethodInfo mInfo; object result; string path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); path = Path.Combine(path, "ClassLibrary1.dll"); byte[] assembly = File.ReadAllBytes(path); //app domain load AppDomain appDomain = AppDomain.CreateDomain("Test Domain"); loadedAssembly = appDomain.Load(assembly); obj = loadedAssembly.CreateInstance("ClassLibrary1.Class 1"); mInfo = obj.GetType().GetMethod("SayHello"); result = mInfo.Invoke(obj, null); Console.WriteLine("Result: {0}", result.ToString()); //Assembly load sample loadedAssembly = Assembly.Load(assembly); obj = loadedAssembly.CreateInstance("ClassLibrary1.Class 1"); mInfo = obj.GetType().GetMethod("SayHello"); result = mInfo.Invoke(obj, null); Console.WriteLine("Result: {0}", result.ToString()); The code for SayHello is return "Hello from " + AppDomain.CurrentDomain.Id.ToString(); Return values are: Hello from 1 Hello from 1 Soo, we were executing on the same app domain that is why everything went smooth. However, if I'll try to create ClassLibrary1 instance on our new domain then I'll receive FileNotFound exception. ( calling ObjectHandle objHandle = appDomain.CreateInstance("ClassLibraray1.dll", "ClassLibrary1.Class1"); ) -- Regards, Vadym Stetsyak. Blog: http://vadmyst.blogspot.com |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |