无法找到'app.xaml',在修改'app.xaml'之前会出现IOException

5
基本上,我遇到了与这个(未解决的)问题相同的问题: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();
            }
            ...
        }
    

可能是重复的问题:IOException was unhandled - Cannot locate resource app.xaml - Tim Pohlmann
2个回答

0

我不确定这是否是一个最终的解决方案,但目前它似乎在工作:

  1. 用记事本打开你的csproj文件
  2. 搜索App.xaml和App.xaml.cs。确保对该文件的每个引用都具有相同的大小写。这些文件被称为App.xaml和App.xaml.cs,所以我将引用保留为这样。

之前我的代码是这样的:

<Compile Include="app.xaml.cs">
  <DependentUpon>App.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

所以我进行了修改,现在它是这样的:

<Compile Include="App.xaml.cs">
  <DependentUpon>App.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

另外一件我做的事情是寻找 BootstrapperPackage 并从那里移除旧版本的 .Net Framework,但如果你的项目使用依赖于旧版本 .Net 的库,那并不是一个好主意。我不确定这是否也造成了问题。

0
当你改变项目的目标框架时,类似这样的事情可能会发生。你可以将项目重新创建为从一开始就以.Net 4为目标的新应用程序,并将所有代码文件添加为现有项目。
还有一件事让人想到的是app.xaml文件名的大小写。在某些情况下可能是区分大小写的,在其他情况下可能不区分大小写,所以你尝试过改变它了吗?在我的系统上,默认名称是App.xaml。由于错误消息中的名称是app.xaml,也许值得在文本编辑器中对项目文件进行区分大小写的搜索,并将所有出现该名称的地方更改为App.xaml。

谢谢你的回答。是的,我想那就是我必须要做的。不管怎样,我正在尝试找到一个“更好”的解释来解决这个错误。 我也考虑过大小写敏感的app.xaml,但在我的项目中没有匹配大小写的'app.xaml'。而且,这也非常不直观,因为我的安装程序也会创建App.xaml而不是app.xaml。 无论如何,如果没有更好的原因,我将非常感激地接受你的答案 :) - Daniel Castro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接