Search code examples
c#visual-studio-2015windows-phone-8.1stack-overflow

System.typeInitializationException on Windows phone


I am getting this exception when I am trying to debug my application by connecting a device. It is working fine in the emulator with no exceptions at all.

The InnerException is: Could not load file or assembly 'BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942' or one of its dependencies. The system cannot find the file specified.

But the file is present with the specific version and token.

In StackTrace it showing that exception is occured here : setDefaultLanguageFromCode(String selectedLanguage)

Here's the code:

 private void Application_Launching(object sender, LaunchingEventArgs e)
    {
     ...//some code

        Utility.setDefaultLanguageFromCode(code);
        Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
        LocalizedStringsInCommonDll.LocalizedStringsResource.UpdateLanguage();
    }

In Utility Page :

 public static System.Globalization.NumberFormatInfo input = new System.Globalization.NumberFormatInfo();
 public static void setDefaultLanguageFromCode(string selectedLanguage)
    {
        input.NumberDecimalSeparator = ".";//**Exception here**
        input.NumberGroupSeparator = ",";
    ......
    }

Is the exception caused due to some settings on device. I tried google search but nothing helped me..

I am desperately in need of help.. I have already wasted an entire day behind this trying to figure out what is wrong here..


Solution

  • I tried to reinstall BouncyCastle crypto by using this in Package manager console

    Install-Package Portable.BouncyCastle -Version 1.8.1.3

    and it resolved my issue..