asp.net-core-mvc-2.0

Trying to Test a Controller with a UrlHelper

▼魔方 西西 提交于 2021-02-16 18:07:17
问题 Trying to create a URLHelper for testing purposes throws a NullReferenceException . Example: [Fact] public async void AuthenticateAsyncTest() { // Arrange var controller = new Controller(serviceProvider) { Url = new UrlHelper(new ActionContext()) // Exception thrown }; // Act var result = await controller.Authenticate() as ViewResult; // Assert Assert.NotNull(result); } Every time I run this Test, the Exception that is thrown in Url = new UrlHelper(new ActionContext()) is: Exception.Message:

No parameterless constructor defined for this object in asp.netcore migrations

北城以北 提交于 2020-01-06 06:19:06
问题 I am new to ASP.NET Core. learning new version of .NET Core 2.0 using VS Code. I got stuck while doing creating database using migration. First, it gives an exception of implementation of IDesignTimeDbContextFactory. After solving this, it still gives an exception of No parameterless constructor defined for this object Here's my code for DbContextClass: public VegaDbContext CreateDbContext(string[] args) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory

visual studio 2017 publish asp.net core

旧街凉风 提交于 2020-01-05 03:41:06
问题 I have Visual Studio 2017 Enterprise 15.3.2 and rather old project made in dotnet core 1.1. If I publish my project in console using 'dotnet publish ....' It works perfectly. But when I use Visual Studio, I can restore, build, run my project absolutely without problems. Only an issue I have when I try to publish using 'Publish..' context menu in the project. I publish the project simply into the folder. Once I make publishing I have suddenly a error and cannot assembly a project. Here is a

File Path for PersistKeysToFileSystem on shared server

南楼画角 提交于 2020-01-04 04:08:07
问题 I'm trying to make my keys persist for users that log in. As I'm currently using shared hosting for the website, I've decided to use the file system to store the keyring. So the code looks like this: services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo("")) .SetApplicationName("MyWebsite") .SetDefaultKeyLifetime(TimeSpan.FromDays(90)) .ProtectKeysWithCertificate(cert); However, what I'm not really understanding is where I should hold these keys, and what would be the path I

How do I write EF.Functions extension method?

Deadly 提交于 2020-01-03 15:33:29
问题 I see that EF Core 2 has EF.Functions property EF Core 2.0 Announcement which can be used by EF Core or providers to define methods that map to database functions or operators so that those can be invoked in LINQ queries . It included LIKE method that gets sent to the database. But I need a different method, SOUNDEX() that is not included. How do I write such a method that passes the function to the database the way DbFunction attribute did in EF6? Or I need to wait for MS to implement it?

ASP .NET Core 2 MVC error NU1202 creating project on VS 2017 and NET CLI

こ雲淡風輕ζ 提交于 2020-01-01 09:58:11
问题 I have installed VS2017 15.3.0 and .NET Core 2.0 and have created a default Web MVC application on VS 2017 and I got the following errors: Error NU1202 Package System.Threading.Overlapped 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Overlapped 4.0.1 supports: netstandard1.3 (.NETStandard,Version=v1.3) Error NU1202 Package System.IO.Compression 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.IO.Compression