Create Views in different project

Topics: Prism v2 - WPF 3.5
Apr 6, 2010 at 7:28 AM

I'm implementing a module with Views created in a separate project and hence a separate assembly. I'm using UnityContainer and DirectoryLookUp for module discovery and placing both the module and view binaries inside modules folder.

All works fine, container is able to resolve and create the view.

I also have a requirement to generate the view type dynamically and load it. For that I'm using Type.GetType("<fully qualified name of type, fully qualified name of assembly>", true). For some strange reason this doesn't work and an exception is thrown at the run time. If view is created in the same assembly in which module resides then Type.GetType works fine.

After debugging, I realised that Module assembly is loaded by calling Assembly.LoadFrom() method inside AssemblyResolve event of AppDomain, however, the view assembly is loaded via. container while resolving the view type. Both the binaries are loaded in AppDomain and AppDomain.CurrentDomain.GetAssemblies(..) returns both of these.

Also, if I explicitely pick up the view assembly from loaded assemblies and then call GetType method on assembly it works fine - the workaround being used currently.

My guess is that it is related to the way container resolves the types. May be container loads the assembly in less privilege or different context. Can somebody please explain what's going "under the hood" and what should be the best way to handle this requirement.

 

Apr 12, 2010 at 7:32 PM

Hi,

From the problem description above, this does not seem to be a problem entirely related to Prism. For that reason you might find it useful to post your question in these forums:

It might also be useful, if you could provide the full exception message you are getting. Based on this documentation, which explains the different exceptions the Type.GetType method can throw, the possible cause for your exception could be narrowed down.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman