Adding System.Web.Ui.WebControls to analyzer test project - .net-core

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.

Related

Could not load file or assembly 'Microsoft.SqlServer.Server'

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

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).

Blazor Core Hosted - all Components in Razor Class Library Project are being printed as HTML on the page

I haven't been able to find the keywords for a similar issue, so I'm posting a new one.
The project was working fine and suddenly the issue described below happened. I was only editing some Razor files from the Razor Class Library, so I was unable to trace it back to any code modification I made.
The Issue:
I have the following project structure:
The Client, Server and Shared are projects that were initially created by the Blazor Template in the NET Core 3.0. DesktopClient is a similar Blazor project with ElectronNET and the issue is also happening on the component over there.The SharedLibrary project is the project where the components common to all projects are placed and where the root of the issue is apparently coming from.
The SharedLibrary is referenced on the Client project so I can access the components in the Client project.
What happened is that suddenly the components from the Razor Class Library stopped being "compiled" and all "#" are being printed as Raw HTML like the button for the "Counter 2":
[]
Notice as how there are 3 buttons on the image. The first one is in the base Razor page and is being compiled correctly. Second one is from the SharedLibrary project and is not being compiled apparently as the "#" tag is not being replaced. And the third button is from a Component in the Client project(same project as the base Razor page) and is also working correctly.
So the issue is that the SharedLibrary Razor files are not being "compiled".
What I've tried:
Remove and add reference from project;
Clean and rebuild solution;
Update packages;
Checked .csproj to see if I could find anything wrong/missing (not experienced on this file, so might have missed something).
Created a new Blazor Core Hosted project and added a Razor Class Library with the same setup as this demo. It worked fine, so the problem in on this project. Dependencies and ".csproj" files seem very similar.
The code:
.csproj for Client project:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazor.Extensions.SignalR" Version="0.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SharedLibrary\SharedLibrary.csproj" />
<ProjectReference Include="..\Shared\ServerAPI.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\SharedLibrary\Content\styles\font\**\*.*">
<Link>wwwroot\styles\font\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\SharedLibrary\Content\images\system\*.*">
<Link>wwwroot\images\system\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\SharedLibrary\Content\images\social\brands\*.*">
<Link>wwwroot\images\social\brands\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Remove="bin\**" />
<Content Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
<Content Remove="compilerconfig.json" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="compilerconfig.json" />
<_ContentIncludedByDefault Remove="wwwroot\styles\main.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Folder Include="Services\" />
<Folder Include="wwwroot\images\system\" />
<Folder Include="wwwroot\scripts\" />
</ItemGroup>
<ItemGroup>
<None Include="compilerconfig.json" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\styles\main.css">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
</Target>
</Project>
.csproj for SharedLibrary
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazor.Extensions.SignalR" Version="0.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\images\social\brands\" />
<Folder Include="Core\Login\" />
<Folder Include="Core\Login\OAuth2\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Languages\en-US.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>en-US.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Languages\en-US.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>en-US.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Index.razor
#page "/"
#using ServerAPI.Client.Components
#using SharedLibrary.Components.User
<h1>Counter</h1>
<p>Current count: #currentCount</p>
<button class="btn btn-primary" #onclick="IncrementCount">Click me</button>
#code {
int currentCount = 0;
void IncrementCount()
{
currentCount++;
}
}
<SocialWithFormLoginComponent />
<Counter />
SocialWithFormLoginComponent.razor in SharedLibrary project
<h1>Counter 2</h1>
<p>Current count 2: #currentCount2</p>
<button class="btn btn-primary" #onclick="IncrementCount2">Click me 2</button>
#code {
int currentCount2 = 0;
void IncrementCount2()
{
currentCount2++;
StateHasChanged();
Console.WriteLine("Hello world!");
}
}
Counter.razor in Client project
<h1>Counter 3</h1>
<p>Current count 3: #currentCount3</p>
<button class="btn btn-primary" #onclick="IncrementCount3">Click me 3</button>
#code {
int currentCount3 = 0;
void IncrementCount3()
{
currentCount3++;
StateHasChanged();
Console.WriteLine("Hello world!");
}
}
Final comments
As you can see the code is very simple for my troubleshooting, however the project is not, so re-creating would be a lot of work.
Any suggestions I might try? I'm really confused here.
Thanks in advance!
Update with solution:
Turns out, as #dani hererra posted, I was missing "_Imports.razor" in the folder on my components from the attached Razor Class library like so:
Check Microsoft.AspNetCore.Components.Web is listed on _Imports.razor:
#using System.Net.Http
#using Microsoft.AspNetCore.Authorization
#using Microsoft.AspNetCore.Components.Authorization
#using Microsoft.AspNetCore.Components.Forms
#using Microsoft.AspNetCore.Components.Routing
#using Microsoft.AspNetCore.Components.Web //<-----
#using Microsoft.JSInterop
#using _your_namespace_
#using _your_namespace_.Shared

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