Skip to content

System.Configuration.ConfigurationErrorsException when usin AppSettings #328

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

Closed
jakzale opened this issue Nov 30, 2017 · 10 comments
Closed

Comments

@jakzale
Copy link

jakzale commented Nov 30, 2017

The following code for accessing AppSettings via ConfigurationManager:

var appSettings = ConfigurationManager.AppSettings;

throws a System.Configuration.ConfigurationErrorsException:

[11/30/2017 6:18:52 PM] A ScriptHost error has occurred
[11/30/2017 6:18:52 PM] Exception while executing function: Status. System.Configuration.ConfigurationManager: Configuration system failed to initialize. System.Configuration.ConfigurationManager: Unrecognized configuration section system.serviceModel. (C:\Users\jakza\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll.config line 204).
[11/30/2017 6:18:52 PM] Exception while executing function: Status
[11/30/2017 6:18:52 PM] Exception while executing function: Status. System.Configuration.ConfigurationManager: Configuration system failed to initialize. System.Configuration.ConfigurationManager: Unrecognized configuration section system.serviceModel. (C:\Users\jakza\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll.config line 204).
[11/30/2017 6:18:52 PM] Function completed (Failure, Id=a559541d-3f8d-4176-b0df-8bb35588e74d, Duration=657579ms)
[11/30/2017 6:18:52 PM]
[11/30/2017 6:18:52 PM] Executed 'Status' (Failed, Id=a559541d-3f8d-4176-b0df-8bb35588e74d)
[11/30/2017 6:18:52 PM] System.Private.CoreLib: Exception while executing function: Status. System.Configuration.ConfigurationManager: Configuration system failed to initialize. System.Configuration.ConfigurationManager: Unrecognized configuration section system.serviceModel. (C:\Users\jakza\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll.config line 204).
[11/30/2017 6:18:52 PM]   Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is 'a559541d-3f8d-4176-b0df-8bb35588e74d'
[11/30/2017 6:18:52 PM] System.Private.CoreLib: Exception while executing function: Status. System.Configuration.ConfigurationManager: Configuration system failed to initialize. System.Configuration.ConfigurationManager: Unrecognized configuration section system.serviceModel. (C:\Users\jakza\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll.config line 204).

It seems that Azure.Functions.Cli.dll.config refers to System.ServiceModel, which appears to be depracated/removed from .Net Core.

Info

Azure Functions Core Tools (2.0.1-beta.21)
Function Runtime Version: 2.0.11370.0

dotnet --version: 2.1.1

@burma-shave
Copy link

Also coming up against this problem.

@follesoe
Copy link

Same, run into this issue when adding a connectionStrings section to the local.settings.json file.

@TheDruidsKeeper
Copy link

I also ran into this issue, and System.Configuration.ConfigurationManager appears to be unusable because of this.

Removing the system.serviceModel section from Azure.Functions.Cli.dll.config stops the error from happening, but the configuration manager doesn't appear load up any of the app settings or connection strings. I wasn't able to find a work around to get the configuration manager working, so instead had to resort to retrieving app settings from the environment variables.

@DOMZE
Copy link

DOMZE commented Jan 5, 2018

I came across the same error when debugging my function locally. Using Azure Functions CLI 2.1.0-beta (installed through the extension in Visual Studio) and I have the SDK v1.0.6

@jongio
Copy link
Member

jongio commented Jan 5, 2018

Also running into this...

image

@fabiocav
Copy link
Member

fabiocav commented Jan 5, 2018

In 2.0, we have moved to the new ASP.NET Core configuration model. We intend to support binding to an IConfiguration instance that will provide a similar API, but in the meantime, the workaround is to read environment variables as opposed to relying on the ConfigurationManager and its APIs.

@jongio
Copy link
Member

jongio commented Jan 8, 2018

See this blog for instructions on how to use AppSettings and ConnectionStrings in v2 https://blog.jongallant.com/2018/01/azure-function-config/

@grahambunce
Copy link

grahambunce commented May 10, 2018

I'm using a third party product (NHiberate) that uses System.Configuration internally. What's the suggestion to work around this?

There is no way for me to adjust their code so I'm pretty much stuck, as I would be if I use any of the other hundreds of packages out there that probably also use ConfigurationManager.

@fabiocav - if I understand you correctly, asking us to use Environment variables or (in future) then use a new configuration api isn't going to be an option where we use third party produces under Azure Functions. There must be an alternative surely?

(btw, NHibernate "just works in ASP.NET Core 2.0" so is there a difference with what you're doing in Azure Functions?)

e.g.:

2018-05-11 09:53:23.61699,3,System.TypeInitializationException
The type initializer for 'NHibernate.NHibernateLogger' threw an exception.
b3eabb26-8be0-4634-9248-8afbeabd8d2b,b3eabb26-8be0-4634-9248-8afbeabd8d2b,5c57409c-a9ad-4a36-9f1b-f3e98e6b5f9c

at NHibernate.NHibernateLogger.For(Type type)
at NHibernate.Cfg.Environment..cctor()

2018-05-11 09:53:23.62025,3,System.Configuration.ConfigurationErrorsException
Configuration system failed to initialize
b3eabb26-8be0-4634-9248-8afbeabd8d2b,5c57409c-a9ad-4a36-9f1b-f3e98e6b5f9c,acf10e30-6618-47ea-8bda-769afb1bd1d2

at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.get_AppSettings()
at NHibernate.NHibernateLogger.GetNhibernateLoggerClass()
at NHibernate.NHibernateLogger..cctor()

2018-05-11 09:53:23.63227,3,System.Configuration.ConfigurationErrorsException
Unrecognized configuration section system.serviceModel. (C:\Users\bunceg\AppData\Local\AzureFunctionsTools\Releases\2.0.1-beta.27\cli\func.dll.config line 204)
b3eabb26-8be0-4634-9248-8afbeabd8d2b,acf10e30-6618-47ea-8bda-769afb1bd1d2,9d7f3f91-345b-4359-8752-daa2d6b92559

at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)

@ahmedelnably
Copy link
Contributor

Closing as stale

@jongio
Copy link
Member

jongio commented Dec 12, 2019

@jimmyca15 - Does AppConfig work with functions and is this a new recommended workaround for this?

@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants