Error: Mapping a form with config.

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

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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
section.Containers"containerOne".Configure(container);
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.
thx!
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!