我最近将我的项目从dotnet core v.1.0.0升级到v.1.0.4。我在每个Startup.cs文件中使用相同的代码。 V.1.0.0工作正常,.4没有。 Visual Studio 2017。
System.ArgumentNullException occurred
HResult=0x80004003
Message=Value cannot be null.
Source=<Cannot evaluate the exception source>
StackTrace:
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
at ApostilleDNCv2.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options) in c:\users\kenn.kinnaird\documents\visual studio 2017\Projects\ApostilleDNCv2\ApostilleDNCv2\Startup.cs:line 34
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TContext](IServiceProvider applicationServiceProvider, Action`2 optionsAction)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
我的代码(两个版本):
Startup.cs -
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ApostillesTest")));
services.AddMvc();
services.AddDistributedMemoryCache();
services.AddScoped<ICountryRepository, CountryRepository>();
appsettings.json -
"ConnectionStrings": {
"ApostillesTest": "Server=TESTSQLCORP;Database=Apostilles;Trusted_Connection=True;Persist Security Info=True",
"DefaultConnection": "Server=TESTSQLCORP;Database=Apostilles;Trusted_Connection=True"
}
我在这里看过其他解决方案;没人帮忙。 任何帮助将不胜感激。