none
Unexpected behaviour with assemblies and type resolution.

    Question

  • Hi;

    If I create a simple console app, in there use Assembly.Load(file_path) to load an assembly, then call Type.GetType(full_type_name), it fails.

    It also fails if I use Load(raw_binary) too.

    I can add an AssemblyResolve handler and pass back the loaded assembly there, but why must I? why cant it see that the assembly has already been loaded?

    Also I noticed that when I load from the raw binary there is no version shown for that assembly in the Visual Studio 'Modules' window...

    Incidentally I do pass the fully qualified (namespace, assembly, version etc) name of the type into GetType.

    Also if I load the assembly, use type = assembly.GetType(shortname) - that works, it finds the type in that assembly, so...if I then take that type and pass its AssemblyQualifiedName property into Type.GetType() that still fails.

    This eliminates any cause due to me messing up the full name spelling etc, this is most odd.

    Thx

    Cap'n





    Thursday, April 26, 2012 7:24 PM

Answers

  • There is no API Assembly.Load(file_path). Did you mean Assembly.LoadFile or Assembly.LoadFrom?

    AFAIK Type.GetType scans only Load context. Therefore nothing loaded into LoadFile context (aka Neither context), nor LoadFrom context will be searched.

    You can learn more about Loader contexts here: http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx

    -Karel

    Friday, April 27, 2012 7:19 AM
  • Hi Captain kernel, 

    Type.GetType( will take simple type name only if the type is in current executing assembly or in Mscorlib.dll (here).

    so in your case you are searching with type name (simple) not in executing assembly but dynamically loaded one obviously cannot locate.

    To search across loaded assemblies, you should provide AssemblyQualifiedName (namespace qualified name).. please check are you passing correct one?

    this will be in the format of (from here)

    TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly,

    Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    Friday, April 27, 2012 8:12 AM

All replies

  • There is no API Assembly.Load(file_path). Did you mean Assembly.LoadFile or Assembly.LoadFrom?

    AFAIK Type.GetType scans only Load context. Therefore nothing loaded into LoadFile context (aka Neither context), nor LoadFrom context will be searched.

    You can learn more about Loader contexts here: http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx

    -Karel

    Friday, April 27, 2012 7:19 AM
  • Hi Captain kernel, 

    Type.GetType( will take simple type name only if the type is in current executing assembly or in Mscorlib.dll (here).

    so in your case you are searching with type name (simple) not in executing assembly but dynamically loaded one obviously cannot locate.

    To search across loaded assemblies, you should provide AssemblyQualifiedName (namespace qualified name).. please check are you passing correct one?

    this will be in the format of (from here)

    TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly,

    Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    Friday, April 27, 2012 8:12 AM
  • Hi Captain kernel, 

    Type.GetType( will take simple type name only if the type is in current executing assembly or in Mscorlib.dll (here).

    so in your case you are searching with type name (simple) not in executing assembly but dynamically loaded one obviously cannot locate.

    To search across loaded assemblies, you should provide AssemblyQualifiedName (namespace qualified name).. please check are you passing correct one?

    this will be in the format of (from here)

    TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly,

    Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    Hi

    My test does actually use the fully qualified name - I am aware of this and do not use the short name.

    Thx

    Cap'n

    Friday, April 27, 2012 12:50 PM
  • There is no API Assembly.Load(file_path). Did you mean Assembly.LoadFile or Assembly.LoadFrom?

    AFAIK Type.GetType scans only Load context. Therefore nothing loaded into LoadFile context (aka Neither context), nor LoadFrom context will be searched.

    You can learn more about Loader contexts here: http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx

    -Karel

    Hi, yes I used LoadFile and LoadFrom (both cause the same failure for Type.GetType() though).

    Let me look into what you say here, this may be the cause.

    Thanks

    Cap'n

    Friday, April 27, 2012 12:52 PM