我有一个简单的WPF应用程序,我想开始。我下面的Microsoft模式与实践复合应用程序指南WPF。然而,我的WPF应用程序与TypeInitializationException立即失败,我跟着他们的指示。
I have a simple WPF application which I am trying to start. I am following the Microsoft Patterns and Practices "Composite Application Guidance for WPF". I've followed their instructions however my WPF application fails immediately with a "TypeInitializationException".
InnerException属性显示,的类型初始System.Windows.Navigation.BaseUriHelper'引发了异常。
The InnerException property reveals that "The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception."
下面是我的App.xaml:
Here is my app.xaml:
<Application x:Class="MyNamespace.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
</Application.Resources>
</Application>
和这里是我的app.xaml.cs(抛出的异常的公共应用程序()):
And here is my app.xaml.cs (exception thrown at "public App()"):
public partial class App : Application
{
public App()
{
Bootstrapper bootStrapper = new Bootstrapper();
bootStrapper.Run();
}
}
我已经设置了应用程序类项目的启动对象。
I have set the "App" class as the startup object in the project.
什么是误入歧途?
感谢@ IMA ,你的答案我指出了正确的方向。我使用一个app.config文件,它包含这样的:
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>
看来问题是在&lt;启动&GT;元素,因为当我删除它的应用程序运行得很好。我很困惑,因为Visual Studio 2008中补充说,当我检查,利用客户端配置文件可以在3.5 SP1中的框。
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>
这工作!
我不知道为什么在App.config元素的顺序是非常重要的 - 但现在看来,这是
I'm not sure why the order of elements in the app.config is important - but it seems it is.