gigiuzzo
gigiuzzo

Reputation: 21

Wpf LoadComponent throws IoException when try to load app.xaml

I'm writing a windows application on .net 5.0. When I try to add something inside <Application.Resources> in app.xaml the application crash on startup saying "System.IO.IOException: 'Cannot locate resource 'app.xaml'.'". I observed that the exception is raised by the next code:

System.Uri resourceLocater = new System.Uri("/Myapplication;component/app.xaml", System.UriKind.Relative);
System.Windows.Application.LoadComponent(this, resourceLocater);

These two lines are automatically added in App.g.i.cs when I write something in <Application.Resources>. I also tried to execute these lines inside the method App.OnStartup, and I get the same exception.

I tried to write this <Application.Resources> :

Case 1:

 <Application.Resources>
                <ResourceDictionary Source="StringResources.xaml"/>
 </Application.Resources>

Case 2:

 <Application.Resources>
        <ResourceDictionary >
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="StringResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
  </Application.Resources>

Case 3:

 <Application.Resources>
        <Style TargetType="Border" x:Key="FancyBorder">
            <Setter Property="Background" Value="#4E1A3D" />
            <Setter Property="BorderThickness" Value="5" />
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush>
                        <GradientStop Offset="0.0" Color="#4E1A3D"/>
                        <GradientStop Offset="1.0" Color="Salmon"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
</Application.Resources>

Upvotes: 0

Views: 354

Answers (1)

gigiuzzo
gigiuzzo

Reputation: 21

The problem was in csproj where I put

<UICulture>en-US</UICulture>

in

 <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <<UICulture>en-US</UICulture>
  </PropertyGroup>

When I deleted the tag UICulture all return to works.

Upvotes: 1

Related Questions