Originally posted by **nickrandolph** March 31, 2023
With the new class library structure it's somewhat difficult to load resources in code.
Uno.Extensions provides a [wrapper](https://github.com/unoplatform/uno.extensions/blob/main/src/Uno.Extensions.Localization.UI/ResourceLoaderStringLocalizer.cs) for this but without this accessing resources from the class library requires two branches of code, one for WinAppSdk that uses ResourceMap and one that uses and overloaded ResourceLoader constructor that takes the name of the class library.
The idea would be to provide an implementation of ResourceManager/ResourceMap in Uno that aligns with the WinAppSdk
Source issue: https://github.com/unoplatform/uno/issues/11786
When not using Uno.Extensions, Windows.ApplicationModel.Resources.ResourceLoader cannot be used under WinAppSDK, Microsoft.Windows.ApplicationModel.Resources.ResourceLoader must be used instead:
#if HAS_UNO
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
#else
var resourceLoader = new Microsoft.Windows.ApplicationModel.Resources.ResourceLoader();
#endif
var myResource = resourceLoader.GetString("ApplicationName");
Discussed in https://github.com/unoplatform/uno/discussions/11867
Workaround
When using Uno.Extensions, using
ResourceLoaderStringLocalizer
abstracts the difference.When not using
Uno.Extensions
,Windows.ApplicationModel.Resources.ResourceLoader
cannot be used under WinAppSDK,Microsoft.Windows.ApplicationModel.Resources.ResourceLoader
must be used instead: