Error: Mapping a form with config.

Apr 28, 2008 at 5:39 AM
Here is my config:
<section name="unity"
Microsoft.Practices.Unity.Configuration, Version=,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<container name="containerOne">
<type type="System.Windows.Forms.Form, System.Windows.Forms,
Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
mapTo="Form2" />

and here is my code:
IUnityContainer container = new UnityContainer();
UnityConfigurationSection section
= (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
Type type = Type.GetType("System.Windows.Forms.Form, System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Form form = container.Resolve<Form>();

and there's a TypeLoadException.
You see I can get the type with Type.GetType before Configure, and it's no problem if I use code to register type but not the config.
Apr 28, 2008 at 7:58 AM

mapTo="Form2" />

You don't say which type is giving the TypeLoadException, but I suspect it's your Form2, not System.Windows.Form. Try fully qualifying Form2 as well (otherwise it's going to try to look for it in Microsoft.Practices.Unity.Configuration).
Apr 28, 2008 at 8:20 AM
Oh, you're right!
I missed that.
thx Chris!