Reputation: 2492
I am trying to put a config file in the PCL portion of my IOS/Android app.
The documentation at: https://github.com/mrbrl/PCLAppConfig suggests:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("DemoApp.App.config")).GetAppSettings;
I expect DemoApp is the assembly name of their sample app so I have:
using PCLAppConfig;
namespace LYG
{
public class App : Application
{
public App ()
{
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("LYG.App.config")).AppSettings;
}
...
}
}
I get the following compile error:
/Users/greg/Projects/LYG/LYG/LYG.cs(122,122): Error CS1061: Type PCLAppConfig.ConfigurationManager' does not contain a definition for
GetAppSettings' and no extension method GetAppSettings' of type
PCLAppConfig.ConfigurationManager' could be found. Are you missing an assembly reference? (CS1061) (LYG)
This is my packages.config file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="PCLAppConfig" version="0.3.1" targetFramework="portable45-net45+win8+wp8" />
<package id="PCLStorage" version="1.0.2" targetFramework="portable45-net45+win8+wp8" />
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="portable45-net45+win8+wp8" />
</packages>
I also tried with parentheses:
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("LYG.App.config")).AppSettings();
Why can't the GetAppSettings be found?
Upvotes: 1
Views: 1550
Reputation: 170
You need to add the PCLAppConfig nuget package to your PCL and platforms projects.
Then I take you are trying to use the resource based app.config; I just updated the documentation to reflect the last version update.
then use:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.Initialise(assembly.GetManifestResourceStream("DemoApp.App.config"));
in doubt, check the demo project on github : https://github.com/mrbrl/PCLAppConfig/tree/master/src/DemoApp
Upvotes: 1