Resource Strings - UWP vs net 5
If you store your display text in a Resources file then most of the documentation that tells you how to retrieve it will be:
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
If you try to use this code in a net 5 WinUI app then it will compile OK, but there will be a runtime error complaining about the use of GetForCurrentView, of the nature of:
System.Runtime.InteropServices.COMException: 'Resource Contexts may not be created on threads that do not have a CoreWindow. (0x80073B27)'
After a bit of digging around I found the equivalent call you need is
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse();
Comments
Post a Comment