Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:18:35+00:00 2026-06-05T20:18:35+00:00

Simple Inject is throwing the following exception when attempting to register my DbContext. The

  • 0

Simple Inject is throwing the following exception when attempting to register my DbContext.

The supplied connection string is not valid, because it contains insufficient mapping or metadata information.
Parameter name: connectionString

I’m new to DI and could be missing something fairly obvious. The connection string looks fine. It is the same one that gets used to create the DbContext normally. I was attempting the solution here

public static class SimpleInjectorInitializer
{
    /// <summary>Initialize the container and register 
    // it as MVC3 Dependency Resolver.</summary>
    public static void Initialize()
    {
        var container = new Container();            
        InitializeContainer(container);
        container.RegisterMvcControllers(
            Assembly.GetExecutingAssembly());            
        container.RegisterMvcAttributeFilterProvider();       
        container.Verify();            
        DependencyResolver.SetResolver(
            new SimpleInjectorDependencyResolver(container));
    }

    private static void InitializeContainer(
        Container container)
    {
    }
}

Update: I still haven’t solved my issue, but it is very similar to this issue with Ninject

Stack Trace:

System.InvalidOperationException was unhandled by user code
  Message=The configuration is invalid. Creating the instance for type _AccountController failed. Error occurred while trying to get an instance of type _AccountController. The type initializer for 'Web.Controllers._AccountController' threw an exception.
  Source=SimpleInjector
  StackTrace:
       at SimpleInjector.Helpers.Verify(IInstanceProducer instanceProducer, Type serviceType)
       at SimpleInjector.Container.ValidateRegistrations()
       at SimpleInjector.Container.Verify()
       at Web.App_Start.SimpleInjectorInitializer.Initialize() in C:\workspace\BrowsarServer\QARSite\Web\App_Start\SimpleInjectorInitializer.cs:line 24
  InnerException: SimpleInjector.ActivationException
       Message=Error occurred while trying to get an instance of type _AccountController. The type initializer for 'Web.Controllers._AccountController' threw an exception.
       Source=SimpleInjector
       StackTrace:
            at SimpleInjector.InstanceProducers.InstanceProducer.ThrowErrorWhileTryingToGetInstanceOfType(Exception innerException)
            at SimpleInjector.InstanceProducers.InstanceProducer.GetInstance()
            at SimpleInjector.Helpers.Verify(IInstanceProducer instanceProducer, Type serviceType)
       InnerException: System.TypeInitializationException
            Message=The type initializer for 'Web.Controllers._AccountController' threw an exception.
            Source=Web
            TypeName=Web.Controllers._AccountController
            StackTrace:
                 at Web.Controllers._AccountController..ctor()
                 at lambda_method(Closure )
                 at SimpleInjector.InstanceProducers.InstanceProducer.GetInstance()
            InnerException: System.ArgumentException
                 Message=The supplied connection string is not valid, because it contains insufficient mapping or metadata information.
Parameter name: connectionString
                 Source=System.Data.Entity
                 ParamName=connectionString
                 StackTrace:
                      at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
                      at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
                      at Web.Models.BrowsarEntities..ctor() in C:\workspace\BrowsarServer\QARSite\Web\Models\Browsar.Designer.cs:line 90
                      at Web.Controllers._AccountController..cctor() in C:\workspace\BrowsarServer\QARSite\Web\Controllers\_AccountController.cs:line 15
                 InnerException: System.InvalidOperationException
                      Message=Unable to determine application context. The ASP.NET application path could not be resolved.
                      Source=System.Data.Entity
                      StackTrace:
                           at System.Data.Metadata.Edm.AspProxy.GetBuildManagerReferencedAssemblies()
                           at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetAllDiscoverableAssemblies()
                           at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetWildcardAssemblies()
                           at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
                           at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
                           at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
                           at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)
                           at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
                           at System.Data.Common.Utils.Memoizer`2.Result.GetValue()
                           at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)
                           at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
                           at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
                           at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
                      InnerException: System.Reflection.TargetInvocationException
                           Message=Exception has been thrown by the target of an invocation.
                           Source=mscorlib
                           StackTrace:
                                at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
                                at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
                                at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
                                at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
                                at System.Data.Metadata.Edm.AspProxy.GetBuildManagerReferencedAssemblies()
                           InnerException: System.InvalidOperationException
                                Message=This method cannot be called during the application's pre-start initialization stage.
                                Source=System.Web
                                StackTrace:
                                     at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
                                     at System.Web.Compilation.BuildManager.GetReferencedAssemblies()
                                InnerException: 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:18:36+00:00Added an answer on June 5, 2026 at 8:18 pm

    The root cause is burried deep down in the inner exceptions. When inspecting the stack trace, you will be able to find the cause of this. The reason is in the following two inner exceptions:

    InvalidOperationException: Unable to determine application context.
    The ASP.NET application path could not be resolved.

    and:

    InvalidOperationException: This method cannot be called during the
    application’s pre-start initialization stage.

    In other words, this exception is caused by a timing problem. I’m not sure if you can change your connection string to solve this, but you can also move your initalization to a later moment in starting the application. You can do this as follows:

    1. Remove the [assembly: WebActivator.PreApplicationStartMethod] (top line) of the SimpleInjectorInitializer.cs class.
    2. Add a call to the SimpleInjectorInitializer.Initialize() method in the Application_Start() event of the global asax.

    After doing this, initializing (and especially, verifying) of the object graph is done after the pre-init state, which seems to be too early for EF in an ASP.NET environment.

    Another option is to remove the container.Verify(); call from the SimpleInjectorInitializer.Initialize method, since it is the early verification process that is killing you. However, please read this Verify the container’s configuration first, to see alternatives, before doing so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple phone book class (this class is extracted because I inject
Simple question - How do I convert a string that has been through parseInt
I have a simple, but probably common problem on how to inject HTML inside
is there some simple way to inject Properties class loaded with a file from
I have trouble running Guice 3 within an OSGi container. Following is a simple
A simple example: class C{} class B{ @Inject C c; void doSomething(){ System.out.println(c); }
In Chrome there is a simple way to inject a dynamically loaded script into
I've got a simple object into which I'm trying to inject properties. I'm unclear
I have following simple page: public class Login extends BasePage { private UserDao userDao;
I have a very simple Vaadin application. I want to inject the main window

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.