5

Basically I'm having the same issue as this (unanswered) question: IOException was unhandled - Cannot locate resource app.xaml

When I open my project in Visual Studio 2010 and start debugging, I get "IOException was unhandled: Cannot locate resource app.xaml". Rebuilding the solution DOES NOT work, I have to somehow modify my app.xaml file (adding an empty line, for example) in order to run my project successfully.

Additional details:

  • 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();
            }
            ...
        }
    
GGMG-he-him
  • 394
  • 1
  • 7
  • 26
Daniel Castro
  • 1,290
  • 2
  • 11
  • 22
  • Possible duplicate of [IOException was unhandled - Cannot locate resource app.xaml](https://stackoverflow.com/questions/7126147/ioexception-was-unhandled-cannot-locate-resource-app-xaml) – Tim Pohlmann Mar 01 '19 at 10:18

2 Answers2

0

Things like this could happen when you change the target framework of a project. You could recreate the projects as new applications which target .Net 4 from the start, and add all your code files as existing items.

Another thing that comes to mind is the casing of the app.xaml file name. It might be case sensitive in some contexts and not case sensitive in others, so have you tried changing that? On my system, by default it is App.xaml. Since in the error message it is app.xaml, it might be worth while doing a case sensitive search through the project files with a text editor and changing all occurences of the name to App.xaml.

hbarck
  • 2,934
  • 13
  • 16
  • Thanks for your answer. Yes, I think that's what I'll have to do. Anyway, I'm trying to find a 'better' explanation to this error. I was thinking about the case sensitive app.xaml too, but there are no 'app.xaml' (case sensitive) matches in my project. Also, it would be very counter-intuitive because my installation also creates App.xaml and not app.xaml. Anyway, if there are no 'better reasons' I will gratefully accept your answer :) – Daniel Castro Dec 09 '12 at 21:46
0

I don't know if this is a definitive solution, but it seems to be working so far:

  1. Open your csproj file with Notepad
  2. Search App.xaml and App.xaml.cs. Ensure every reference to this file has the same case. The files were called App.xaml and App.xaml.cs, so I left the references like that.

Previously I had something like this:

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

So I modified it and now it is:

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

Another thing I did was look for BootstrapperPackage and remove the old versions of .Net Framework from there, though I don't think that's a good idea if your project uses libraries that depend on old versions of .Net. I'm not sure that was causing the problem too.

Daniel Castro
  • 1,290
  • 2
  • 11
  • 22