You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code for changing culture leads to occasional app-crashing exception #397
The code described above in a few samples for changing the Language capability will randomly throw this error:
'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
This is within try/catch and crashes the application. Tried to run the deployed application with a native debugger attached, when the problem arose the application hung for about two minutes then crashed with an access violation.
This occurs for all three variations:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
Windows.ApplicationModel.Resources.Core.ResourceContext.SetGlobalQualifierValue("Language", "de-DE");
resourceContext.QualifierValues["Language"] = "de-DE";
This is on version 16299 for project, Win10 version 1709 build 17025.1000 with Windows SDKs 10.0.15063.468, 10.0.15063.674, 10.1.16299.15, and 10.1.17046.1000 installed.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 45dd1537-4655-f121-dd0a-71b7ed12cbac
Version Independent ID: 7128e83a-daaf-da16-0baf-119e9a4f4a33
Thanks, Evan, for the thorough details! Your code looks right; the only potential corner case here is obtaining the ResourceContext for the current view from a background thread. Is it possible your code is doing that? You'd have to guard that otherwise an exception will be thrown ('Resource Contexts may not be created on threads that do not have a CoreWindow. (Exception from HRESULT: 0x80073B27)').
if (Windows.UI.Core.CoreWindow.GetForCurrentThread() != null)
{
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
}
However, you're seeing an access violation. Please let me know whether the above info helps at all.
Stuck the calls for the change inside of the if block you suggested (it's being requested on user click > binding > command on viewmodel).
These both led to the access violation:
resourceContext.QualifierValues["language"] = "de-DE";
resourceContext.Languages = new string[] { "de-DE" };
This one I'm about 150 clicks back and forth on 5 different runs of the app and it's all working like a charm so far:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
So I can't say it's not going to throw an access violation tomorrow, but it seems to be working. Thanks for the quick response, will update further if this ends up throwing any issues when we get to deeper integration testing.
Activity
stevewhims commentedon Mar 29, 2018
Thanks, Evan, for the thorough details! Your code looks right; the only potential corner case here is obtaining the ResourceContext for the current view from a background thread. Is it possible your code is doing that? You'd have to guard that otherwise an exception will be thrown ('Resource Contexts may not be created on threads that do not have a CoreWindow. (Exception from HRESULT: 0x80073B27)').
if (Windows.UI.Core.CoreWindow.GetForCurrentThread() != null)
{
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
}
However, you're seeing an access violation. Please let me know whether the above info helps at all.
EvanHutnick commentedon Mar 30, 2018
Wanted to update, we have progress. :)
Stuck the calls for the change inside of the if block you suggested (it's being requested on user click > binding > command on viewmodel).
These both led to the access violation:
resourceContext.QualifierValues["language"] = "de-DE";
resourceContext.Languages = new string[] { "de-DE" };
This one I'm about 150 clicks back and forth on 5 different runs of the app and it's all working like a charm so far:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
So I can't say it's not going to throw an access violation tomorrow, but it seems to be working. Thanks for the quick response, will update further if this ends up throwing any issues when we get to deeper integration testing.
stevewhims commentedon Mar 30, 2018
That's great to hear, Evan, thanks for your update! Please reopen this issue if necessary; I'll close it for the time being.
Merge pull request #397 from MicrosoftDocs/master637051287536113520
Docs updates for 1.11 release (#397)
Main > Live (#448)
Toc update (#457)
Sync main and live (#458)
troubleshooting: clarify WSL `startingDirectory` entry (#516)
Merge Main > Live (#549)
Merge main into live (#555)
Main > Live sync (#565)
Merge main > Live (#599)