Loading an Assembly not in my current appdomain.

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I wan't to be able to deserialize a class from an assembly that is not in
the application domain. To do that I must have the Type from the Assembly.
How do you get a Type from an assembly that is not in the manifest of the
current AppDomain. I have tried different ways but get exceptions from all
of them that say the:

assembly or one of its dependancies could not be found.

There must be missing something.
 
Hi Mark,

Thank you for posting in the community!

Based on my understanding, you want to use some class in an assembly which
has not been loaded into your application's appdomain.

=====================================
Actually, to explicitly load assemblies into appdomain, .Net provides you 3
methods to do this: Assembly.Load(), Assembly.LoadFrom(),
Assembly.LoadWithPartialName(). Please refer to the document of them in the
MSDN.

I suggest you always use Assembly.Load to accomplish your loading work,
because:

Assembly.Load()
1). If the assembly is strong named, Assembly.Load() will use assembly
name, version, culture and public key token to identify the assembly. The
CLR will first look in GAC, then in application's base directory, last in
private path directory.
2). If the assembly is weekly named, Assembly.Load(), the CLR will not look
in GAC.
3). You should pass the assembly name to the Load() method(Without file
extension)

Assembly.LoadFrom()
You pass the pathname of the assembly(With file extension), and can not
contains strong-name information, and the CLR does not search in GAC for
you.

Assembly.LoadWithPartialName()
You should always avoid using this method, because an application will not
know for sure what version it is loading.

For more information, please refer to "CLR Hosting, AppDomain, and
Reflection" in Jeffrey Richter's "Applied .Net Framework Programming".

After you have loaded the assembly, you can use reflection to use the class
in that assembly.(For example, use Assembly.GetType() to get the type of
the class)

==========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I assume that by 'deserialize' you mean 'load'?

Than you have to load the assembly which has your class.
If the class has some static fields with types that are in the other
assemblies it is quite possible that you will get the 'assembly or one of
its dependancies could not be found.' error, because runtime couldn't found
that assemblies.

You can use Reflector tool ( http://www.aisto.com/roeder/dotnet ) to obtain
the dependant assemblies.
 
Back
Top