Type.GetType fails to create type from already loaded assembly?

In order to understand why this doesn't work, you need to understand the issue of "load contexts". Type. GetType only looks at the "Load" context.

The assembly you loaded into memory was in the "LoadFrom" context.

In order to understand why this doesn't work, you need to understand the issue of "load contexts". Type. GetType only looks at the "Load" context.

The assembly you loaded into memory was in the "LoadFrom" context. The only way to really get binds in the load context to see assemblies in the load-from context is to use the AssemblyResolve event and write code to return the correct assembly. The AssemblyResolve event fires right before the bind fails and all other assembly lookup did not succeed.

See the following links for more information about load contexts and issues that arise when using LoadFrom. MSDN - msdn.microsoft.com/en-us/library/dd15378... AssemblyResolve - http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx Suzanne Cook - http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx.

A tried using Assembly. Load(AssemblyName. GetAssemblyName(file)).

The assembly loads fine (the rest of the program seems to work), but the exception in the Type. GetType stays the same. – MatÄ›j Zábský Oct 24 '10 at 17:58 Now it works (after I added the directory where the assemblies are into app.

Config). Thanks for an explanation of thw area of . NET I had no clue about.

– MatÄ›j Zábský Oct 24 '10 at 18:26 Right, the AssemblyName returned by GetAssemblyName will get you the strong name of the assembly but then when that is passed to Assembly. Load, the normal assembly probing rules are followed. So as you've noted, it only works if the runtime can find the assembly which may involve app.

Config probing hints. – Josh Einstein Oct 24 '10 at 19:15.

If you can get the assembly using Assembly. LoadFrom then you can get the type by doing: Assembly assembly = Assembly. LoadFrom("whatever"); Type myType = assembly.

GetType("typeName") The assembly. GetType has other overloads which you can find out about here.

1 +1 Good pragmatic solution. He still may run into issues if other code attempts to load other types in the same assembly via the load context without AssemblyResolve though. Unfortunately, LoadFrom just has a while bunch of unexpected side-effects that are hard to work around.

– Josh Einstein Oct 24 '10 at 17:30.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions