Type.GetType does do what you think it does, but if you used LoadFrom that
puts your loaded assembly into the 'LoadFrom' context and normal type
resolution won't be able to find it.

It's a much better idea to find a way to NOT use LoadFrom and if you do, use
this instead which works how you want it:

AssemblyName name = AssemblyName.GetAssemblyName( "C:\\your.dll" );
Assembly.Load( name );

// this will now work
Type type = Type.GetType( "your.type, your.assembly, Version=xxx,
Culture=xxx, PublicKeyToken=xxx" );

The first two from Suzanne Cook should provide more info:
http://www.google.com/search?q=.net+loadfrom+context&rls=com.microsoft:*&ie=
UTF-8&oe=UTF-8&startIndex=&startPage=1

Adam..

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
Sent: Friday, June 06, 2008 2:23 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Reflection, Type.GetType(...) and
Activator.CreateInstance

I'm having difficulty getting Type.GetType(...) and Activator.CreateInstance
working.

I've loaded an assembly into the AppDomain using Assembly.LoadFrom(...).  I
can look at the AppDomain.GetAssemblies() method and see that the assembly
is loaded.  However, when I try to create a type from that assembly I get
this exception:

Could not load file or assembly 'xxxxxxxxx, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system
cannot find the file specified.
However, if I use the Assembly object from the AppDomain.GetAssemblies()
method and execute the CreateInstance() method it works.

Any ideas what's going on here?

I was under the impression that Type.GetType(...) searched the AppDomain for
the assembly.

Thanks,
Mike

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to