2017-12-28 21 views
0

SQL 데이터베이스를 추가 할 때 Startup.cs에서 오류가 발생하고 잃어 버렸습니다. 내가 입력 :ASP.Net Core - GetRequiredService에서 SqlServer를 설정하면 오류가 발생합니다.

services.AddDbContext<ModelContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection"))); 

실제로 나는 program.cs에서 그것을 얻는다. 그러나 에러는 위의 선에서 기인한다. 발신자는 : 오류 메시지가

var context = services.GetRequiredService<ModelContext>(); 

입니다

:

Method 'Clone' 
in type 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension' 
from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation. 

오류 소스는 다음과 같습니다

Microsoft.EntityFrameworkCore.SqlServer 

전체 오류 메시지 :

+  Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} 
     HResult -2146233054 int 
     HelpLink null string 
+  InnerException null System.Exception 
     Message "Method 'Clone' in type 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation." string 
     Source "Microsoft.EntityFrameworkCore.SqlServer" string 
     StackTrace " at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer\r\n at FltCandidates.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options) in C:\\Users\\garry\\source\\repos\\FltCandidates\\FltCandidates\\Startup.cs:line 35\r\n at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass0_0`1.<AddDbContext>b__0(IServiceProvider p, DbContextOptionsBuilder b)\r\n at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TContext](IServiceProvider applicationServiceProvider, Action`2 optionsAction)\r\n at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass5_0`1.<AddCoreServices>b__0(IServiceProvider p)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)\r\n at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider)\r\n at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)\r\n at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)\r\n at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)\r\n at FltCandidates.Program.Main(String[] args) in C:\\Users\\garry\\source\\repos\\FltCandidates\\FltCandidates\\Program.cs:line 26" string 
+  TargetSite {System.Reflection.RuntimeMethodInfo} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo} 
     TypeName "Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension" string 

내 .CSProj가 포함

<PropertyGroup> 
    <TargetFramework>netcoreapp2.0</TargetFramework> 
    </PropertyGroup> 

    <ItemGroup> 
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" /> 
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.5" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.1" /> 
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" /> 
    </ItemGroup> 

    <ItemGroup> 
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" /> 
    </ItemGroup> 

모든 모든 도움은 질문 아래 코멘트에 대답했다

질문

을 감상 할 수있다. SqlServer 설치가 끝났지 만, 어떤 이유로 NuGet에 표시되지 않았습니다. SqlServer의 최신 버전을 설치하자마자 NuGet은 "invisible"을 이미 설치 한 SqlServer를 업데이트해야했습니다.

+0

올바른 CandidateContext를 추가하고 ModelContext를 가져 오려고합니까? – cloudikka

+0

미안하지만, 나는 모두 CandidateContext 였고, 나는 그것들을 모두 ModelContext로 이름을 바꾼다 고 생각했다. 내가 생각하기에 좀 더 표준적인 방식으로 그것을 더 쉽게 볼 수 있도록 텍스트에서 편집했습니다. – Monofuse

+1

그래, 문제는 아마도 [Microsoft.EntityFrameworkCore.SqlServer] (https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/) nuget 패키지 버전입니다. 최신 버전의 EF Core에서 1.1.5.0 이전 버전을 사용하려고합니다. 2.0.1로 업데이트하십시오. – cloudikka

답변

1

파일 모양이 .CSproj인데, 사용자의 파일은 Microsoft.EntityFrameworkCore.SqlServer 패키지가 설치되어 있지 않은 .Net Core 2 프로젝트입니다.

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" /> 

이 패키지는 현재 버전은 1.1.5이며 Microsoft.EntityFrameworkCore.SqlServer에 대해 동일한 버전을 설치한다 Microsoft.EntityFrameworkCore.SqlServer.Desing에 대한 종속성이 또한 : 당신이 유사한 줄을 없기 때문에 알 수 있습니다. 이 문제는 Clone() 메서드가 Entity Framework Core 2에만 존재한다는 것입니다. 즉, Microsoft.EntityFrameworkCore.SqlServer 패키지를 2.0.1 버전으로 설치하거나 업데이트해야합니다. 이 버전은 Microsoft.EntityFrameworkCore.SqlServer.Desing과 호환됩니다.

희망이 있습니다.

+0

질문은 아래 질문에 답변되었습니다. SqlServer 설치가 끝났지 만, 어떤 이유로 NuGet에 표시되지 않았습니다. SqlServer의 최신 버전을 설치하자마자 NuGet은 "invisible"을 이미 설치 한 SqlServer를 업데이트해야했습니다. – Monofuse