title: Change the app language programmatically - UWP
body: <p>I have created resource files (<code>.resw</code>) for French and English. Now I want to call resource file for "fr" on loading the first page of my app. I have done like below. But it shows an exception </p>
  
  <blockquote>
    <p>"System.NullReferenceException: Object reference not set to an
    instance of an object".</p>
  </blockquote>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;TextBlock x:Uid="txt_launch3" Grid.Row="4"  Padding="7"/&gt;
  </code></pre>
  
  <p><strong>Code-behind</strong></p>
  
  <pre><code>public sealed partial class MainPage : Page
  {
      public MainPage()
      {    
         this.InitializeComponent();
         string getDeviceDefaultLang="fr";
         ChangeLanguage2(getDeviceDefaultLang);    
      }
  
      private void ChangeLanguage2(string language)
      {
          try
          {
              ApplicationLanguages.PrimaryLanguageOverride =language;
              Frame.CacheSize = 0;
           Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();          Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
              Frame.Navigate(this.GetType());
          }
          catch (Exception ex)
          {
              string exx = ex.ToString(); //getting System.NullReferenceException            
          }
      }
   }
  </code></pre>