Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

IConfiguration.Get throwing "Cannot create instance of type 'System.String' because it is missing a public parameterless constructor." #343

Closed
@Daniel15

Description

@Daniel15

I'm trying to upgrade a site from Beta 6 to RC 1. The site uses Entity Framework 6 so I need to manually load the connection string from the config file. I have a line of code that looks like this:

config.Get("Data:DefaultConnection:ConnectionString")

This is throwing Cannot create instance of type 'System.String' because it is missing a public parameterless constructor.

Stack:

   at Microsoft.Extensions.Configuration.ConfigurationBinder.CreateInstance(Type type)
   at Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(Type type, Object instance, IConfiguration config)
   at Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type)
   at Microsoft.Extensions.Configuration.ConfigurationBinder.Get[T](IConfiguration configuration, T defaultValue)
   at Daniel15.Data.DatabaseContext..ctor(IConfiguration config) in C:\Users\danlo\Documents\Visual Studio 2015\Projects\dan.cx\Daniel15.Data\DatabaseContext.cs:line 40

Config is a .json file that looks like:

{
  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=192.168.146.1; Database=daniel15_site; Uid=dev; Pwd=password;"
    }
  }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions