Azure-functions-core-tools: System.Configuration.ConfigurationErrorsException when usin AppSettings

Created on 30 Nov 2017  路  10Comments  路  Source: Azure/azure-functions-core-tools

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

Most helpful comment

Also coming up against this problem.

All 10 comments

Also coming up against this problem.

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

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.

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

Also running into this...

image

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.

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

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\AzureFunctionsToolsReleases\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)

Closing as stale

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

Was this page helpful?
0 / 5 - 0 ratings