Could not load file or assembly 'Microsoft.SqlServer.Server' - asp.net

I am trying to make a simple insert into my sqlserver database using Dapper. This is my code:
using var db = DbContext.CreateConnection();
db.Open();
string sqlQuery =
"INSERT INTO Account (Id, Balance, NumberOfTransactions) VALUES(#Id, #Balance, #NumberOfTransactions)";
int rowsAffected = db.Execute(sqlQuery, entity);
return rowsAffected > 0;
And this is my DapperContext.
public DapperContext(IConfiguration configuration)
{
_configuration = configuration;
_connectionString = _configuration.GetConnectionString("DapperConnection");
}
public IDbConnection CreateConnection()
=> new SqlConnection(_connectionString);
But when I reach the Execute line I am getting Could not load file or assembly 'Microsoft.SqlServer.Server'. I have no idea why. My SQLServer is being hosted by a docker image. And I've already installed the Server nuget. Here's the list of nugets that I currently have installed:
<PackageReference Include="Akka" Version="1.4.39" />
<PackageReference Include="Akka.DependencyInjection" Version="1.4.39" />
<PackageReference Include="Akka.Remote" Version="1.4.39" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper.EntityFramework" Version="2.0.90" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.0-preview3.22168.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-preview.5.22302.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.5.22302.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-preview.5.22302.2" />
<PackageReference Include="Microsoft.SqlServer.Server" Version="1.0.0" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="160.600.9-ctp2p0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
Anyone can help me what might be wrong here and why do I keep getting this could not load error? I even already download SQL Server from Microsoft but my idea was to use my docker container instead.
Stack trace:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified.
File name: 'Microsoft.SqlServer.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'

I was using the wrong version of the nuget package. I had to replace PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.0-preview3.22168.1 with PackageReference Include="System.Data.SqlClient" Version="4.8.3" and it worked right away

Related

ASP.NET Core 6 MVC and Entity Framework Core 7.0 - can't connect to Sqlite

I just upgraded from EF 6 -> EF Core 7 in my ASP.NET Core 6 MVC app because I needed the context.Database.SqlQuery<T>() functionality; however, when I try to run any query via EF it now appears unable to connect at all when I build & run or execute migration cmds:
C:\Path\To\My\Project\Ui>dotnet ef database update --context sqliteascertodbcontext
Build started...
Build succeeded.
Debug: Registered integration with EF Core.
An error occurred using the connection to database 'main' on server 'C:\Path\To\My\Project\Ui\db.sqlite3'.
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: ''.
at Microsoft.Data.Sqlite.SqliteConnection.LoadExtensionCore(String file, String proc)
at Microsoft.Data.Sqlite.SqliteConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteScalar(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
SQLite Error 1: ''.
CSProject contents:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.11" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />
<PackageReference Include="Microsoft.Owin" Version="4.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.17.0" />
<PackageReference Include="Microsoft.Owin.Security" Version="4.2.0" />
<PackageReference Include="Microsoft.Owin.Security.OAuth" Version="4.2.0" />
<PackageReference Include="Microsoft.Owin.Security.Jwt" Version="4.2.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.23.1" />
<PackageReference Include="Sentry.AspNetCore" Version="3.22.0" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.3" />
<PackageReference Include="VueCliMiddleware" Version="3.1.2" />
</ItemGroup>
Is there anything missing, or?

Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting'

Running my integration tests for some controllers, I get this exception:
Error Message:
System.TypeLoadException : Could not load type 'Context' from assembly
'Microsoft.AspNetCore.Hosting, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I've already checked this but not helpful
Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting, Version=3.0.0.0
Here's the list of dependencies in unit test proj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\src\MyMicroserviceActio.Api\appsettings.json" Link="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.7.142" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MyMicroserviceActio.Api\MyMicroserviceActio.Api.csproj" />
</ItemGroup>
</Project>
And here's an example of a test case:
private readonly TestServer _server;
private readonly HttpClient _client;
public HomeControllerTests()
{
_server = new TestServer(WebHost.CreateDefaultBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
[Fact]
public async Task home_controller_get_should_return_string_content()
{
var response = await _client.GetAsync("/");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
content.Should().BeEquivalentTo("Hello from MyMicroserviceActio API!");
}
The whole project is github
You need to bump Microsoft.AspNetCore.TestHost to a compatible 3.x version (PR submitted).

Adding System.Web.Ui.WebControls to analyzer test project

TL:DR -- How do I add System.Web.Ui.WebControls to my AdhocWorkspace?
Long version...
My unit test for an analyzer is failing because the test compilation environment doesn't have a reference to System.Web.Ui.WebControls. I need to get a semantic type, and that is failing because it doesn't know what the type is.
My test project is core2.0:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
</ItemGroup>
My DiagnosticVerifier has:
private static readonly MetadataReference CorlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
private static readonly MetadataReference SystemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location);
private static readonly MetadataReference CSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location);
private static readonly MetadataReference VBLangSymbolsReference = MetadataReference.CreateFromFile(typeof(VisualBasicCompilation).Assembly.Location);
private static readonly MetadataReference CodeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location);
private static readonly MetadataReference SystemData = MetadataReference.CreateFromFile(typeof(System.Data.DataRow).Assembly.Location);
private static readonly MetadataReference SystemWeb = MetadataReference.CreateFromFile(typeof(System.Web.HttpUtility).Assembly.Location);
And adds them to the workspace via:
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.AddMetadataReference(projectId, CorlibReference)
.AddMetadataReference(projectId, SystemCoreReference)
.AddMetadataReference(projectId, CSharpSymbolsReference)
.AddMetadataReference(projectId, VBLangSymbolsReference)
.AddMetadataReference(projectId, CodeAnalysisReference)
.AddMetadataReference(projectId, SystemData)
.AddMetadataReference(projectId, SystemWeb)
But I'm still getting a Type 'Label' not is not defined from context.Compilation.GetDiagnostics(), which prevents me from determining what the type of the label.Text.
I solved this by creating 2 new references obtained from the .net framework in the 'c:\program files (x86)\reference assemblies\microsoft\framework.netframework\v4.0\' directory and loading from the path.
So, I commented out
.AddMetadataReference(projectId, CorlibReference)
.AddMetadataReference(projectId, SystemCoreReference)
and added in
.AddMetadataReference(projectId, SystemCore)
.AddMetadataReference(projectId, SystemReference)
I also changed the SystemWeb reference to be gathered from the same directory. After that it worked.

IdentityServer4 and ASP.NET Core 2.0

I must be missing something but I cannot see it.
I have created a new 'empty' ASP.NET Core 2.0 Project
I added EF Core 2.0 and EF Core 2.0 Identity
I then try to add IdentityServer4 2.0 rc1 and I get a package restore failure with the following error message:
Error occurred while restoring NuGet packages: Sequence contains more
than one matching element
There is no code in this project so I am completely confused.
Here is the csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="2.0.0-rc1-update1" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<PackageReference Include="NETStandard.Library" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
Here is my call to NuGet.org from the Package Manager Console:
PM> Install-Package IdentityServer4.AspNetIdentity -Version 2.0.0-rc1
-Prerelease GET https://api.nuget.org/v3/registration3-gz-semver2/identityserver4.aspnetidentity/index.json
OK
https://api.nuget.org/v3/registration3-gz-semver2/identityserver4.aspnetidentity/index.json
484ms Restoring packages for
D:\ProtoTypes\IdentityServer4\IdentityServer4\IdentityServer4.csproj...
Install-Package : Sequence contains more than one matching element At
line:1 char:1
+ Install-Package IdentityServer4.AspNetIdentity -Version 2.0.0-rc1 -Pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:03.7728514 PM>
Following are some changes that you will migrate your project to asp.net core 2.0.
Step 1:
Download asp.net core 2.0 gx64x for visual studio 2017 from the following link.https://www.microsoft.com/net/download/core
Step 2:
Download from Nuget packages or from package manager console
1-Install-Package IdentityServer4 -Version 2.0.0
2-Install-Package IdentityServer4.AspNetIdentity -Version 2.0.0-rc1-update2
Step 3:
Update Some Code in Csproj file.
Before:
netcoreapp1.1
After:
netcoreapp2.0
Before:
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" />
After:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
Before:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
 
After:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
Step 4:
Update in Program.cs Class
Before:
public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup()
        .Build();
 
    host.Run();
}
 
After:
public static void Main(string[] args)
{
    BuildWebHost(args).Run();
}
 
public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
           .UseStartup()
           .Build();
Step 5:
Update in StartUp.cs
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddAspNetIdentity<ApplicationUser>();
Before:
app.UseIdentity();
After:
app.UseAuthentication();
Step 6:Changes in Manage Login ViewModel
Before:
public IList<AuthenticationDescription> OtherLogins { get; set; }
 
After:
public IList<AuthenticationScheme> OtherLogins { get; set; }
Step 7:
Changes in Manager Controller
Before:
var otherLogins = _signInManager
                  .GetExternalAuthenticationSchemes()
                  .Where(auth => userLogins
                                 .All(ul => auth.AuthenticationScheme != ul.LoginProvider))
                  .ToList();
 
After:
var otherLogins = (await _signInManager
                   .GetExternalAuthenticationSchemesAsync())
                  .Where(auth => userLogins
                                 .All(ul => auth.Name != ul.LoginProvider))
                  .ToList();
Step 8:
Change sin Login.cshtml file
Before:
var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList();
 
After:
var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList();
Before:
<button type="submit" class="btn btn-default"
        name="provider" value="#provider.AuthenticationScheme"
        title="Log in using your #provider.DisplayName account">
    #provider.AuthenticationScheme
</button>
 
After:
<button type="submit" class="btn btn-default"
        name="provider" value="#provider.Name"
        title="Log in using your #provider.DisplayName account">
    #provider.Name
</button>

Value cannot be null. Parameter Name: connectionstring - when trying to switch to MSSQL from SQLITE

I get this beauty when I am trying to switch to MSSQL database which I installed on my local machine.
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuil
der, String connectionString, Action`1 sqlServerOptionsAction)
at MSBlog.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TConte
xt](IServiceProvider applicationServiceProvider, Action`2 optionsAction)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCa
llSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvide
r provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider prov
ider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider p
rovider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCa
llSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitClosedIEnumerable(ClosedIEnume
rableCallSite closedIEnumerableCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite tr
ansientCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvide
r provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider prov
ider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider p
rovider)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.GetContextTypes()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.GetContextTypesImpl()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: connectionString
"ConnectionStrings": {
"DefaultConenction" : "Server=localhost;Database=db;User Id=user;Password=pw;Trusted_Connection=True;",
"OldConnection": "DataSource=.\\some.db"
},
I also changed the AddDbContext call in Startup.cs to:
services.AddDbContext<ApplicationDbContext>( options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
And lastly I just added my new models to the ApplicationDbContext as DbSets.
What am I doing wrong?
Any command I run that starts with dotnet ef results in the error above and I can't figure out what is null.
These are the versions I am running:
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild3-final" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
Please help!
Correct the spelling of DefaultConenction in your configuration.

Resources