Entity Framework 6 - Intermittent Runtime Error Reading AppSettings from Config

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
Hey folks, I've tried searching for solutions to this on the web and either I'm the only one experiencing this or the search criteria are too broad based on the details involved :|

I have an application running which makes use of Entity Framework 6 and basic threading. It's quite typical. The connection string is stored under <connsectionStrings> in the app.config and I have a few custom app settings in <appSettings>. Nothing fancy. I never write to the config and only read from it - it never undergoes any changes while the app is running at any point in time, ever.

VB.NET:
<appSettings>
    <add key="Localisation:Culture" value="en" />
    <add key="Node:SystemKey" value="380549f2-b969-429d-907e-dbf54d185906" />
  </appSettings>
Now, whether as a Debug or Release level compilation, the application runs perfectly fine without any hassles. The problem is I've noticed that every now and again, randomly, threads will raise exceptions and log the following message:
(HRESULT:0x80131902). System.Configuration.ConfigurationErrorsException: The configuration section 'appSettings' has an unexpected declaration.
This confuses the daylights outta me since it runs well otherwise, the config never changes, etc. A sample stack trace is below.

VB.NET:
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
   at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
   at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
Has anyone ever experienced something like this? I tend to think something is locking the app.config or else I haven't the faintest idea :(
 

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
I have made a couple of changes to my implementation which has resulted in a different method of disposing of my wrapper objects which appears to have helped a bit but I am still getting these intermittent errors, albeit at a lesser rate. Have actually gotten an additional config error of a different form. Totally stumped by this.

As additional info I'm running the app on multiple industrial PC's using Windows 7 embedded, .NET 4.5 and EF 6.
 

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
Unfortunately I'm still having this problem but I'm picking up a bit of a pattern now which has hopefully led me closer to a resolution (of sorts).

Whenever these weird configuration error occur there are two threads that error out at basically the exact same time (give or take 20 milliseconds at most). This leads me to believe that when two threads access the configuration at the same time this is when the error occurs.

Now, whenever the application accesses the configuration for normal purposes it calls RefreshSection() on AppSettings before reading any values so that the configuration can be dynamically changed at runtime. I'm thinking that either the error is due to RefreshSection() being called just before a thread begins accessing the configuration to create an ObjectContext OR accessing the configuration with multiple threads at the same time is the cause.

I'm going to remove all references to RefreshSection() and see what happens.
 
Top Bottom