1

I'm trying to add an in memory store for my ASP.NET 5 application.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    services.AddEntityFramework()
        .AddInMemoryStore()
        .AddDbContext<MyDbContext>();
}

Though I'm getting the following error:

$ dnx . kestrel
* Assertion at loader.c:1189, condition `!mono_loader_get_last_error ()' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at Nalie.Startup.ConfigureServices (Microsoft.Framework.DependencyInjection.IServiceCollection) <0x0003a>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>
* Assertion at loader.c:1912, condition `!mono_loader_get_last_error ()' not met

Abort trap: 6

1 Answer 1

1

You need to update the AddDbContext call to specify which provider to use.

AddDbContext<MyDbContext>(options => options.UseInMemoryDatabase());

The call to AddInMemory just setups up the services required for that data store in DI, but you still need to tell the context which provider to use. This becomes clearer if you see something a little more complex.

services.AddEntityFramework() .AddInMemoryStore() .AddSqlServer() .AddDbContext<MyDbContext>(options => options.UseInMemroryDatabase()) .AddDbContext<MyOtherDbContext>(options => options.UseSqlServer("<connection string>"));

InMemory is a little unique in that it doesn't require any configuration to be used (unlike other providers that require a connection string). So we did consider making InMemory just be selected by default if it is the only provider registered... but that seemed very much like a special case that would just hinder folks understanding of how things work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.