InvalidOperationException was thrown when run the following code.
```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;
namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }
[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }
class Program
{
static void Main(string[] args)
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
using (var context = new EFTestEntities()) // throw InvalidOperationException
{
// some operation
}
}
}
}
```
![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=entityframework&WorkItemId=2827&FileAttachmentId=1490951)
Thrown InvalidOperationException:
```
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The default DbConfiguration instance was used by the Entity Framework before the 'MyDbConfiguration' type was discovered. An instance of 'MyDbConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at EFTest.EFTestEntities..ctor() at d:\EFTest\EFTest\EFTestEntities.Context.cs:line 18
at EFTest.Program.Main(String[] args) at d:\EFTest\EFTest\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
```
Environment
.NET: 4.5
EF: 6.1.3
VS: 2012
Workaround:
```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;
namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }
[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }
class Program
{
static void Main(string[] args)
{
using (var context = new EFTestEntities())
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
// some operation
}
}
}
}
```
Does anyone have any suggestions?
```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;
namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }
[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }
class Program
{
static void Main(string[] args)
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
using (var context = new EFTestEntities()) // throw InvalidOperationException
{
// some operation
}
}
}
}
```
![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=entityframework&WorkItemId=2827&FileAttachmentId=1490951)
Thrown InvalidOperationException:
```
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The default DbConfiguration instance was used by the Entity Framework before the 'MyDbConfiguration' type was discovered. An instance of 'MyDbConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at EFTest.EFTestEntities..ctor() at d:\EFTest\EFTest\EFTestEntities.Context.cs:line 18
at EFTest.Program.Main(String[] args) at d:\EFTest\EFTest\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
```
Environment
.NET: 4.5
EF: 6.1.3
VS: 2012
Workaround:
```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;
namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }
[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }
class Program
{
static void Main(string[] args)
{
using (var context = new EFTestEntities())
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
// some operation
}
}
}
}
```
Does anyone have any suggestions?