Skip to content

Code for changing culture leads to occasional app-crashing exception #397

Closed

Description

@EvanHutnick

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.

Activity

  1. stevewhims commented on Mar 29, 2018

    @stevewhims
    Contributor

    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.

  2. EvanHutnick commented on Mar 30, 2018

    @EvanHutnick
    Author

    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.

  3. stevewhims commented on Mar 30, 2018

    @stevewhims
    Contributor

    That's great to hear, Evan, thanks for your update! Please reopen this issue if necessary; I'll close it for the time being.

  4. added a commit that references this issue on Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions