基本上,我遇到了与这个(未解决的)问题相同的问题:IOException was unhandled - Cannot locate resource app.xaml
当我在Visual Studio 2010中打开我的项目并开始调试时,会出现“IOException was unhandled: Cannot locate resource app.xaml”的错误。重建解决方案不起作用,我必须以某种方式修改我的app.xaml文件(例如添加一个空行),才能成功运行我的项目。
附加细节:
- My solution consists of two projects: My main (WPF) application and a test project.
- I have read about issues if the solution was converted from Visual Studio 2005. This is not my case. My project was originally created with Visual Studio 2010. Maybe (I don't remind exactly) it was sometime targetted at .Net Framework 3.5 or .Net Framework 4.0 Client Profile, but it currently is configured to work with .Net Framework 4.0
- Both projects have different names, if that matters. The first is called MyApplicationName (assembly name and default namespace) and the second MyApplicationName.Test (assembly name and default namespace too)
- Most classes in my main project are internal (including the View classes), but my App class is public
- The main project exposes its internal components to the test project (using
[assembly: InternalsVisibleTo("MyOtherProject")]
) - I'm using MVVM (with MVVM Light), but I'm not using a ViewModel 'resolver'/container/bootstrapper/MEF or related things. I just map my ViewModels to their respective views using DataTemplates and create my ViewModels manually (if that matters).
My App.xaml includes other three xaml resource files. I include my App.xaml here:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources/StyleDictionary.xaml" /> <ResourceDictionary Source="Resources/CommonResources.xaml" /> <ResourceDictionary Source="Resources/ViewModelMappings.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
I override the OnStartup method from my App class to manually handle the startup logic, if that matters. I also wrote a static constructor there to initialize the DispatcherHelper from MVVM Light:
public partial class App : Application { static App() { GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize(); } ... }