C
C#2mo ago
Shady

I'm crashing out at .NET MAUI Localization

I followed these steps https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/localization?view=net-maui-9.0#vs-code-setup And still it gives the same error: MainPage.xaml(9,17): XamlC error XC0000: Cannot resolve type "clr-namespace:[MyApp].Resources.Strings:AppResources". Is it because I'm on Linux and not using VS?
Localization - .NET MAUI
Learn how to localize .NET MAUI app strings, images, and app names.
3 Replies
Shady
ShadyOP2mo ago
<ItemGroup>
<EmbeddedResource Update="Resources/Strings/AppResources.resx">
<Generator>MSBuild:Compile</Generator>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>[MyApp].Resources.Strings</StronglyTypedNamespace>
<StronglyTypedFileName>$(IntermediateOutputPath)/Resource.Designer.cs</StronglyTypedFileName>
<StronglyTypedClassName>AppResources</StronglyTypedClassName>
</EmbeddedResource>

<Compile Include="$(IntermediateOutputPath)/Resource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>false</DesignTime>
<DependentUpon>Resources/Strings/AppResources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources/Strings/AppResources.resx">
<Generator>MSBuild:Compile</Generator>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>[MyApp].Resources.Strings</StronglyTypedNamespace>
<StronglyTypedFileName>$(IntermediateOutputPath)/Resource.Designer.cs</StronglyTypedFileName>
<StronglyTypedClassName>AppResources</StronglyTypedClassName>
</EmbeddedResource>

<Compile Include="$(IntermediateOutputPath)/Resource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>false</DesignTime>
<DependentUpon>Resources/Strings/AppResources.resx</DependentUpon>
</Compile>
</ItemGroup>
Shady
ShadyOP2mo ago
No description
Shady
ShadyOP2mo ago
MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="[MyApp].MainPage"
xmlns:strings="clr-namespace:[MyApp].Resources.Strings">
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="[MyApp].MainPage"
xmlns:strings="clr-namespace:[MyApp].Resources.Strings">
I can see the Resource.Designer.cs file being generated:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace [MyApp].Resources.Strings {
using System;


/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// This class was generated by MSBuild using the GenerateResource task.
/// To add or remove a member, edit your .resx file then rerun MSBuild.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class AppResources {
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace [MyApp].Resources.Strings {
using System;


/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// This class was generated by MSBuild using the GenerateResource task.
/// To add or remove a member, edit your .resx file then rerun MSBuild.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class AppResources {
obj/Debug/net9.0-android/Resource.Designer.cs Is it maybe the command I'm using incomplete? dotnet build -t:Run -f net9.0-android
<ItemGroup>
<EmbeddedResource Update="Resources/Strings/AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>[MyApp].Resources.Strings</StronglyTypedNamespace>
<!-- The error was here, fixed by changing `Resource.Designer.cs` to `AppResources.Designer.cs` to match the class name -->
<StronglyTypedFileName>$(IntermediateOutputPath)/AppResources.Designer.cs</StronglyTypedFileName>
<StronglyTypedClassName>AppResources</StronglyTypedClassName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources/Strings/AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>[MyApp].Resources.Strings</StronglyTypedNamespace>
<!-- The error was here, fixed by changing `Resource.Designer.cs` to `AppResources.Designer.cs` to match the class name -->
<StronglyTypedFileName>$(IntermediateOutputPath)/AppResources.Designer.cs</StronglyTypedFileName>
<StronglyTypedClassName>AppResources</StronglyTypedClassName>
</EmbeddedResource>
</ItemGroup>
This is all what you need to add to your .csproj to add localization. I'm going to cry now...

Did you find this page helpful?