asp.net-core-2.0

Getting “Could not resolve a service of type ..” after upgrading to Core 2 Preview 2

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:37:48
问题 I've just upgraded to ASP.NET Core 2 Preview 2 and ran into a problem with the depedency injection. I get Could not resolve a service of type 'LC.Tools.API.Data.GenericDbContext' for the parameter 'context' of method 'Configure' on type 'LC.Tools.API.Startup' when running the project. I didn't have this problem when using the old version. DbContext (GenericDbContext): namespace LC.Tools.API.Data { public class GenericDbContext : DbContext { public GenericDbContext(DbContextOptions

.Net Core 2.0 and xUnit doesn't run

女生的网名这么多〃 提交于 2019-12-10 09:45:04
问题 VS2017 + Core 2.0. Created a brand new XUnit test project from template .csproj file: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.console" Version="2.3

Asp.NET Core 2 Authentication. SignInManager.PasswordSignInAsync() succeeds, but User.Identity.IsAuthenticated is false

夙愿已清 提交于 2019-12-10 09:34:42
问题 I was following some tutorials on IdentityUser, and I think I did exactly as in tutorials, but when I try to login, I get "MyIdentity: False" (with LogInformation) even thou _signInManager succeeds, which seems to be very weird. I tried to set the users as confirmed, but with no result. I'm working on Visual Studio on Mac. Here's how I register my users: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<IActionResult> Register(RegisterViewModel model) { if (ModelState

Is services.AddSingleton<IConfiguration> really needed in .net core 2 API

有些话、适合烂在心里 提交于 2019-12-10 09:24:30
问题 I accessed appsettings.json In .NET Core 2 Web API Controller simply by adding below: public class MyController : Controller { private readonly IConfiguration appConfig; public MyController(IConfiguration configuration) { appConfig = configuration; } } Without adding below in Startup class ConfigureServices(IServiceCollection services) after services.AddMvc();: services.AddSingleton<IConfiguration>(Configuration); Is there any flaws in my approach? In official docs for .Net Core 2

Is it possible/sensible to split ASP.Net Core 2 (.NET Framework) Web Api into Class Library and Hosting projects?

寵の児 提交于 2019-12-10 04:29:42
问题 I'm trying to port an existing WCF Web API (targeting .NET Framework 4.6.1) to ASP.Net Core 2 using Visual Studio 2017 (v15.4.5) and am having trouble figuring out good/common/supported ways to organize projects, and what types of project they should be. For example: Single project for Server and Hosting, or Class Library for Server and Console application for Hosting Windows Classic Desktop project for Console application and (new style csproj) Web Application for Server library, or both Web

BadImageFormatException when migrating from ASP.Net Core 1.1 to 2.0

落花浮王杯 提交于 2019-12-10 02:56:35
问题 I just migrated an ASP.Net Core 1.1 application to the new 2.0 version that was just released. Now I get the following exception: System.BadImageFormatException: 'Could not load file or assembly 'dotnet-aspnet-codegenerator-design' or one of its dependencies. An attempt was made to load a program with an incorrect format.' The exception is thrown on the following line ( AddMvc ): public IServiceProvider ConfigureServices(IServiceCollection services) { ... services.AddMvc(options => { options

Execute SQL command in Entity Framework Core 2.0 to delete all data in a table

前提是你 提交于 2019-12-10 00:50:25
问题 I want to execute an SQL command from Entity Framework Core 2.0, but I can't figure out how to do so. 1.- The reason why I need to, is that I want to delete all data from a database table, and using Context.remove or Context.removeRange would produce many calls to DB (one for each data in the table). 2.- I've read that there is a method .ExecuteSqlCommand to accomplish that, but that method is not present in my Context.Database (maybe in Core 2.0 it was removed?). Here is the source of the

Unable to send embedded image in email using FluentEmail

醉酒当歌 提交于 2019-12-09 16:45:10
问题 I'm using FluentEmail in ASP.NET core 2.0 class library which will be sending the Email notification. Below is the sample code I have tried till now: using FluentEmail.Core; using FluentEmail.Razor; using FluentEmail.Smtp; using System; using System.IO; using System.Net.Mail; using System.Net.Mime; namespace FluentEmail { public class EmailNotification : IEmailNotification { public bool SendEmailNotification() { try { //Setup Default sender befault sending the email. SmtpClient smtpClient =

.Net Core 2.0 - Get AAD access token to use with Microsoft Graph

北城以北 提交于 2019-12-09 06:32:15
问题 When starting up a fresh .Net Core 2.0 project with Azure AD Authentication you get a working sample that can sign in to your tenant, great! Now I want to get an access token for the signed in user and use that to work with Microsoft Graph API. I am not finding any documentation on how to achieve this. I just want a simple way to get an access token and access the graph API, using the template created when you start a new .NET Core 2.0 project. From there I should be able to figure out the

Connection was closed error between HttpClient and ASP.NET Core 2.0 webservice

我是研究僧i 提交于 2019-12-09 06:14:49
问题 I have a ASP.NET Core 2.0 webservice running on IIS. One of controller's methods looks more or less like this: [HttpGet()] public IActionResult Test() { // do some db updates and get data var result = DoSomeStuff(); // serialize data to byte array var output = Serialize(result); return File(output, "application/octet-stream"); } It does some database updates, query records from a table, serialize data and send them as a response. Data are sent in binary format. I'm using MessagePack-CSharp as