Open johnsonwangnz opened 7 years ago
@johnsonwangnz Hi, what is your platform that you test it? which version of PCLApp do you use?
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.
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. :)
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
@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. :)
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 .
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()));
@AllFallD0wn Did you write ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
before LoadApplication
?
Did you see Usage of library?
@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
FOR FILE SYSTEM APP.CONFIG In MainActivity.cs if (ConfigurationManager.AppSettings == null) { ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current); }
@Nick-Case Ok, Please share App.xaml.cs
thanks
Just try to change the BuildAction of the config file. Right click on the App.config > Properties > Build Action = Embedded resource
@johnsonwangnz Did you problem is resolved?
@johnsonwangnz Please close issue if your issue was resoled
thanks
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