Cannot locate resource 'app.xaml'

Sam Wheat 501 Reputation points
2022-05-18T17:59:37.88+00:00

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>
Developer technologies | Windows Presentation Foundation
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,681 Reputation points Microsoft External Staff
    2022-05-19T06:16:15.107+00:00

    You could try to check the properties of app.xaml . The correct settings are shown in the attached image. If there is any problem, please let me know;
    203582-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.