It has been fifteen years since this problem was posted, perhaps longer:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/447b8017-47b6-4ae4-a658-a9cb6ef08f0e/cannot-locate-resource-window1xaml?forum=wpf
Environment:
.net 6
Visual Studio 2022 17.2
Problem: Defining a resource in App.xaml causes the error below.
The exact naming and type of resouce that is used to re-create the problem is unknown and inconsistent.
System.IO.IOException
HResult=0x80131620
Message=Cannot locate resource 'app.xaml'.
Source=PresentationFramework
StackTrace:
at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at MS.Internal.IO.Packaging.PackagePartExtensions.GetSeekableStream(PackagePart packPart, FileMode mode, FileAccess access)
at MS.Internal.IO.Packaging.PackagePartExtensions.GetSeekableStream(PackagePart packPart)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Oaktree.Summit.Desktop.App.InitializeComponent() in C:\Source\SomeProject\App.xaml:line 1
at Oaktree.Summit.Desktop.App.Main()
Setting the startupuri does not work
Clean + rebuild + delete bin/obj folders does not work (!)
Works:
<local:ApplicationBase x:Class="SomeProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SomeProject.Converters"
xmlns:local="clr-namespace:SomeProject" >
<Application.Resources>
</Application.Resources>
</local:ApplicationBase>
Works:
<local:ApplicationBase x:Class="SomeProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SomeProject.Converters"
xmlns:local="clr-namespace:SomeProject" >
<Application.Resources>
<SolidColorBrush Color="Black" x:Key="BlackBrush"/>
</Application.Resources>
</local:ApplicationBase>
Works:
<local:ApplicationBase x:Class="SomeProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SomeProject.Converters"
xmlns:local="clr-namespace:SomeProject" >
<Application.Resources>
<SolidColorBrush Color="Black" x:Key="BlackBrush"/>
<converters:BoolToTotalsVisibilityConverter x:Key="BoolToTotalsVisibilityConverter"/>
</Application.Resources>
</local:ApplicationBase>
Works:
<local:ApplicationBase x:Class="SomeProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SomeProject.Converters"
xmlns:local="clr-namespace:SomeProject" >
<Application.Resources>
<converters:BoolToTotalsVisibilityConverter x:Key="BoolToTotalsVisibilityConverter"/>
<SolidColorBrush Color="Black" x:Key="BlackBrush"/>
</Application.Resources>
</local:ApplicationBase>
Error:
<local:ApplicationBase x:Class="SomeProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SomeProject.Converters"
xmlns:local="clr-namespace:SomeProject" >
<Application.Resources>
<converters:BoolToTotalsVisibilityConverter x:Key="BoolToTotalsVisibilityConverter"/>
</Application.Resources>
</local:ApplicationBase>