Reputation: 675
I was tasked with making this third party software run on our server, but we only have partial access to the code, the rest exists only as pre-compiled libraries. One of those libraries throws enigmatic exceptions and I can't figure out why. I am completely oblivious to Visual Studio and C#, and this is making no sense at all to me.
What I initially get is:
Unhandled Exception:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'GroupsImporter.Program' threw an exception. --->
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize --->
System.Configuration.ConfigurationErrorsException: Unrecognized configuration section ThirdPartyCompany.Framework.Core.Configuration.v1.2. (Y:\path-to-executable\GroupsImporter.exe.Config line 67)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
The configuration file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler"/>
<section name="AdWords.Common.Configuration" type="AdWords.Common.Configuration.AdWordsConfiguration, AdWords.Common"/>
</configSections>
<appSettings>
...
</appSettings>
<AdWords.Common.Configuration Budget ="xxx" CPC="xxx" EstoqueMinimo="x">
...
</AdWords.Common.Configuration>
<AdWordsApi>
...
</AdWordsApi>
<system.web>
...
</system.web>
<system.net>
...
</system.net>
<ThirdPartyCompany.Framework.Core.Configuration.v1.2>
...
</ThirdPartyCompany.Framework.Core.Configuration.v1.2>
</configuration>
In turn if I remove the section it is complaining about, I get this:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'GroupsImporter.Program' threw an exception. --->
System.Configuration.ConfigurationException: Configuraton section ThirdPartyCompany.Framework.Core.Configuration.v1.2 could not be found.
at ThirdPartyCompany.Framework.Core.Guard.Against[TException](Boolean assertion, String message)
at ThirdPartyCompany.Framework.Core.Configuration.ConfigurationSection.GetConfiguration()
at ThirdPartyCompany.Framework.Core.IoCContainerWrapper.Implementation.IoCThirdPartyCompanyContainer.loadRegisterConfiguration()
//And the stack goes on...
I have no idea on how to solve this issue. I don't have access to the code where the ServiceConfig class is implemented or where the config is consumed. Any ideas about what is going on, and how to fix this issue?
Edit: It was supposedly working on the company's server exactly as provided.
Upvotes: 0
Views: 1851
Reputation: 779
I had the same error with a different dll, the message was:
"Unrecognized configuration section AdWordsApi"
I fix it reinstalling the references AdWordsApi using nuget console.
From Nuget Package Manager Console execute:
Install-Package Google.AdWords
It will reinstall the package and add the following code in app.config
<configSections>
<section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler" />
</configSections>
Upvotes: 0
Reputation: 193
You must be sure that you reference those libraries or ask which one implements the class "ConfigurtionSection" that the system complains about.
Can't post answers: Yeah, the only way you can add custom configuration sections (not app keys) as far as I know is by inheriting from ConfigurationSection class
Upvotes: 1
Reputation: 65079
IIRC, you need to add the section to the configSections
tag.
So, exactly like this one:
<section name="AdWordsApi"
...but you also need:
<section name="ThirdPartyCompany.Framework.Core.Configuration.v1.2" ...
Upvotes: 1