8
votes

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

1
I have attempted to create Xamarin.Forms UWP with .NetStandard 2.0.But I could not reproduce your issue and AppResources works in my side. Could share a simple sample that can reproduce this issue ? - Nico Zhu - MSFT
Thank. I created a small test app and the, UWP works. The ResourceManager looks like in the Full app (null for resource set and filled WinRT part). I will write the solution, if I find the difference betweeen the test and full app. - WebDucer
I found the reason. 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 classen [assembly: NeutralResourcesLanguage("de-DE")] - WebDucer
Greatly helpful, you may converter your comment into the answer for this issue, And mark it as accepted to convenient people who visit this thread later, Thanks for understanding. - Nico Zhu - MSFT
@WebDucer Thanks, that fixed it! I set <NeutralLanguage>en-US</NeutralLanguage> in my .NET Standard class lib and it started working. - kspearrin

1 Answers

10
votes

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.