In a UWP application using WebView2, the CoreWebView2 method returns null after changing the region at runtime in C#

Jay 100 Reputation points
2024-09-03T12:56:53.57+00:00

The CoreWebView2 method works fine the first time, but after changing the app region, the CoreWebView2 method returns null after initialization. Please help to fix this issue.

Code:

XAML

 <muxc:WebView2 x:Name="PDFViewer" NavigationStarting="PDFViewer_NavigationStarting" Margin="0" 
                NavigationCompleted="PDFViewer_NavigationCompleted" Visibility="Visible"/>

CS file

PDFViewer.CoreWebView2

await PDFViewer.EnsureCoreWebView2Async();
PDFViewer.CoreWebView2.SetVirtualHostNameToFolderMapping("mi.Pdf", pdfFolder.Path, CoreWebView2HostResourceAccessKind.Allow);

I have change region in below function

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;


Exception:

User's image

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Jay 100 Reputation points
    2024-09-16T06:54:26.4933333+00:00

    Issue resolved: It works when we set the application region in the App.xaml.cs or ExtendedSplash.xaml.cs files.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.