2

Introduction

I am creating my first Xamarin app (that will target UWP first, then Android, finally maybe iOS).

Basically, the app needs multiple languages: English (Default), French, Spanish, Russian and Swedish at least.

I am trying to add less Platform specific code, so no specific code has been added, for localization.

I used the UseResxLocaliaztion Xamarin GitHub project with the Xamarin Localization Documentation.

Basically, I just copy and try to use this project resources on mine. But namespace was UsingResxLocalization.Resx and mine is WhoStart.Resources, same for the folder name which is Resources instead of Resx.

I updated the ResourceManager property of the Designer.cs file, and try different things with the resx properties, like change the Generator and the CustomToolNamespace with no results.

I manually changed the WhoStart.projitems file in some points since my VisualStudio didn't indent files and can't generate the Designer.cs file.

My environment

  • Windows 10 v1607 Anniversary Update (14393.1066)
  • Visual Studio 2017 v15.1 (26403.7)
  • Xamarin 4.4.0.34
  • NuGet packages :
    • Xamarin.Forms 2.3.4.231
    • Microsoft.NETCore.UniversalWindowsPlatform 5.3.3

The problem

I am having a System.Resources.MissingManifestResourceException when trying to access a resource propety.

MainPage.xaml.cs

Debug.WriteLine(AppResources.AddButton);

System.Resources.MissingManifestResourceException : 'Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WhoStart.Resources.AppResources.resources" was correctly embedded or linked into assembly "WhoStart.UWP" at compile time, or that all the satellite assemblies required are loadable and fully signed.'

Visual Studio

I thougth maybe it cames from my environment :

  • When I create a resource file with Visual Studio wizard, it creates a .resw file.
  • Visual Studio don't autogenerate the Designer.cs file
  • When I open the .resx file, the Access Modifier menu is disabled.
  • It seems that I don't have all project properties I noticed on forums
  • I don't have a "Run Custom Tool" when right clicking a .resx file

The code

AppResources.resx

<?xml version="1.0" encoding="utf-8"?>
<root>
    <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
        <value>2.0</value>
    </resheader>
    <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>

    <data name="AddButton" xml:space="preserve">
        <value>Add new item</value>
        <comment>this string appears on a button to add a new item to the list</comment>
    </data>
</root>

MainPage.xaml.cs

namespace WhoStart.Resources {
    using System.Reflection;


    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class AppResources {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal AppResources() {
        }

        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WhoStart.Resources.AppResources", typeof(AppResources).GetTypeInfo().Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }

        /// <summary>
        ///   Looks up a localized string similar to Add new item.
        /// </summary>
        internal static string AddButton {
            get {
                return ResourceManager.GetString("AddButton", resourceCulture);
            }
        }
    }
}

WhoStart.projitems

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
    <HasSharedItems>true</HasSharedItems>
    <SharedGUID>2f09a751-1235-4d87-8839-d5828319ad81</SharedGUID>
  </PropertyGroup>
  <PropertyGroup Label="Configuration">
    <Import_RootNamespace>WhoStart</Import_RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)ColorUtil.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)ILocalize.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
      <DependentUpon>MainPage.xaml</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.es.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.fr.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)TranslateExtension.cs" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)MainPage.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.es.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.fr.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
  </ItemGroup>
</Project>

Research

Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Quentame
  • 254
  • 1
  • 4
  • 13
  • Have you set the `Build Action` of resx file property as `Embedded Resource`? – Nico Zhu May 10 '17 at 02:08
  • As you can see in the `WhoStart.projitems` file, yes I did :) I post this file too to check if the properties are right, maybe they are. I just don't hope a Visual Studio 2017 bug ... – Quentame May 10 '17 at 07:28

0 Answers0