Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms UWP with .NetStandard 2.0 and null resources

We are currently moving our Xamarin projects from PCL to .Net Standard 2.0, also core library project format. Most things works well. We use resx-files in the core project for localization. This works fine on iOS and Android.

On UWP I get null as value, if I try to access the string ressources

var buttonText = AppResources.Cancel; // => null

The PCL version the same code worked well. Is there some initialization needed?

On debug I can see that the resource manager has a null ResourceSet, but _WinRTResourceManager is filled.

enter image description here

like image 365
WebDucer Avatar asked Nov 14 '17 13:11

WebDucer


1 Answers

Finally I found the reason.

By converting PCL library to .Net Standar normally the file AssemblyInfo.cs is not there. So the neutral language definition get lost.

We use German (de-DE) as default language. As soon as I change the default langugage in Package.appxmanifest from the default value en-US to de-DE the resources from .Net Standard library could not be read.

The fix is, to define explixit the NeutralResourcesLanguage for the .Net Standard library (to the same as UWP project). This can be done in manually created AssemblyInfo.cs (do not forget to turn off auto generation of AssemblyInfo) or declare this info in one of the exsisting classes with [assembly: NeutralResourcesLanguage("de-DE")].

After this fix the resources from .Net Standard library are used correctly also in UWP.

like image 161
WebDucer Avatar answered Nov 02 '22 01:11

WebDucer