WPF Application fails on startup with TypeInitializationException
Thanks @ima, your answer pointed me in the right direction. I was using an app.config file and it contained this:
<configuration> <startup> <supportedRuntime version="v2.0.50727" sku="Client"/> </startup> <configSections> <section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/> </configSections> <modules> <module assemblyFile="Modules/MyNamespace.Modules.ModuleName.dll" moduleType="MyNamespace.Modules.ModuleName.ModuleClass" moduleName="Name"/> </modules></configuration>
It seems the problem was the <startup> element because when I removed it the application ran fine. I was confused because Visual Studio 2008 added that when I checked the box to utilise the "Client Profile" available in 3.5 SP1.
After some mucking about checking and un-checking the box I ended up with a configuration file like this:
<configuration> <configSections> <section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/> </configSections> <modules> <module assemblyFile="Modules/MyNamespace.Modules.ModuleName.dll" moduleType="MyNamespace.Modules.ModuleName.ModuleClass" moduleName="Name"/> </modules> <startup> <supportedRuntime version="v2.0.50727" sku="Client"/> </startup></configuration>
Which works!
I'm not sure why the order of elements in the app.config is important - but it seems it is.