Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes when app resumes #10

Open
johnsonwangnz opened this issue May 11, 2017 · 14 comments
Open

Crashes when app resumes #10

johnsonwangnz opened this issue May 11, 2017 · 14 comments

Comments

@johnsonwangnz
Copy link

First initialization is ok, but after that the same initialization call throws exception
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'ConfigurationManager' threw an exception. occurred

@soroshsabz
Copy link
Contributor

@johnsonwangnz Hi, what is your platform that you test it? which version of PCLApp do you use?

@johnsonwangnz
Copy link
Author

I ma using vs 2017, Android 7.1 -API 25 x86, the place initialization was done is in shared portable resources. I have not tried other platforms.

@soroshsabz
Copy link
Contributor

soroshsabz commented May 18, 2017

ITNOA

@johnsonwangnz what is your meaning about 'same initialization'? Did you mean call

ConfigurationManager.Initialise(assembly.GetManifestResourceStream("DemoApp.App.config")); twice?

If you prevent to reinitializing of ConfigurationManager, Did you have any problem in using ConfigurationManager after resuming app?

Please try this branch from nuget if you have same problem again, tell me please. :)

@johnsonwangnz
Copy link
Author

Yes I put following code in App constructor in pcl
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.Initialise(assembly.GetManifestResourceStream("DemoApp.App.config"));
then every time app resumes, it will be executed again, the second line is where the exception is, I have implemented the reading of App.config into a property myself using similar idea, I only added a test to see if that property already loaded then no need to read again. So it might be just a check,
Cheers

@SunainaDG
Copy link

SunainaDG commented Nov 20, 2017

@johnsonwangnz : Probably you have a workaround by now or maybe you already have a fix for this. But just so that someone else can get some help out of this, try checking if you already have your namevalue collection loaded before you initialize. ex:

if(ConfigurationManager.AppSettings == null)
ConfigurationManager.Initialise(assembly.GetManifestResourceStream("DemoApp.App.config"));

Hope this helps. :)

@johnsonwangnz
Copy link
Author

johnsonwangnz commented Nov 20, 2017 via email

@Nick-Case
Copy link

Managed to recreate this. When I put in the null check, it stopped throwing at PCL App.cs level, and threw in MainActivity.cs at:
LoadApplication(new App(new AndroidInitializer()));

@soroshsabz
Copy link
Contributor

@AllFallD0wn Did you write ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current); before LoadApplication?

Did you see Usage of library?

@Nick-Case
Copy link

@soroshsabz I was following the usage for Embedded App.Config, not File System App.Config:

var a = typeof(App).GetTypeInfo().Assembly;
if (ConfigurationManager.AppSettings == null)
{
    ConfigurationManager.Initialise(a.GetManifestResourceStream("App.config"));
}

This resulted in the above exception when resuming the application

@phamthanhtong
Copy link

FOR FILE SYSTEM APP.CONFIG
In MainActivity.cs
if (ConfigurationManager.AppSettings == null)
{
ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
}

@soroshsabz
Copy link
Contributor

@Nick-Case Ok, Please share App.xaml.cs

thanks

@nemok002
Copy link

nemok002 commented Apr 1, 2022

Just try to change the BuildAction of the config file.
Right click on the App.config > Properties > Build Action = Embedded resource

imagen

@soroshsabz
Copy link
Contributor

@johnsonwangnz Did you problem is resolved?

@soroshsabz
Copy link
Contributor

@johnsonwangnz Please close issue if your issue was resoled

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants