mrbrl / PCLAppConfig

Xamarin.Forms PCL App.Config Manager
Apache License 2.0
21 stars 10 forks source link

Crashes when app resumes #10

Open johnsonwangnz opened 7 years ago

johnsonwangnz commented 7 years ago

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 commented 7 years ago

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

johnsonwangnz commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

@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 commented 6 years ago

Thanks

On Tue, Nov 21, 2017 at 9:27 AM, SunainaDG notifications@github.com wrote:

@johnsonwangnz https://github.com/johnsonwangnz : Probably you have 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. :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mrbrl/PCLAppConfig/issues/10#issuecomment-345821104, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbK4Z4qZXuct8slyfRxi2AExut3yTymks5s4eClgaJpZM4NXf5b .

Nick-Case commented 6 years ago

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 commented 6 years ago

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

Did you see Usage of library?

Nick-Case commented 6 years ago

@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 commented 6 years ago

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

soroshsabz commented 4 years ago

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

thanks

nemok002 commented 2 years ago

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

imagen

soroshsabz commented 2 years ago

@johnsonwangnz Did you problem is resolved?

soroshsabz commented 2 years ago

@johnsonwangnz Please close issue if your issue was resoled

thanks