2017-05-31 1 views
0

Ich habe versucht, IdentityServer4 Version 1.5.2 für ein paar Tage jetzt ohne Erfolg zu funktionieren. Ich verwende VS2017 Meine Entity-Klassen, DataContexts, Repositorys und Migrationen sind resident in einer .Net-Standardbibliothek (1.6). So weit so gut, außer wenn ich update-migration-Befehl für "PersistenGrantDbContext" und "ConfigurationDbCOntext" ausführe. Ich erhalte die FehlermeldungUpdate Migrationsbefehl schlägt fehl für ConfigurationDbContext und PersistentGrantDbContext

Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. 

Datacontext Klassen, die ich erstellt selbst scheinen nicht, dieses Problem zu haben, nachdem „IDbContextFactory“ Schnittstelle Hier habe ich die Umsetzung für die beiden Täter

public class TemporaryDbContextFactoryScopes : IDbContextFactory<PersistedGrantDbContext> 
{ 
    public PersistedGrantDbContext Create(DbContextFactoryOptions options) 
    { 
     var builder = new DbContextOptionsBuilder<PersistedGrantDbContext>(); 
     builder.UseSqlServer("Server=-------;Database=-----------;Trusted_Connection=True;MultipleActiveResultSets=true", 
      optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(UserDbContext).GetTypeInfo().Assembly.GetName().Name)); 
     return new PersistedGrantDbContext(builder.Options, new OperationalStoreOptions()); 
    } 
} 

public class TemporaryDbContextFactoryOperational : IDbContextFactory<ConfigurationDbContext> 
{ 
    public ConfigurationDbContext Create(DbContextFactoryOptions options) 
    { 
     var builder = new DbContextOptionsBuilder<ConfigurationDbContext>(); 
     builder.UseSqlServer("Server=---------;Database=--------;Trusted_Connection=True;MultipleActiveResultSets=true", 
      optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(UserDbContext).GetTypeInfo().Assembly.GetName().Name)); 

     return new ConfigurationDbContext(builder.Options, new ConfigurationStoreOptions()); 
    } 
} 

Umsetzung Ich habe installiert die neueste Version von System.Data.SqlClient immer noch nicht funktioniert

+0

und die Versionsnummer der neuesten einem hilft, ist 4.1.0.0 wie die Fehlermeldungen? – Mashton

+0

Nein, die neueste Version ist 4.3.1, aber ich habe es vor einiger Zeit mit unorthodoxen Mitteln gelöst –

Antwort

0

Ich wollte nur teilen, was ich getan habe, um die Dinge ins Rollen zu bringen. Nicht sicher, ob das der richtige Ansatz ist zwar Zuerst habe ich diese Bibliothek in der Klasse hat CSPROJ

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> 
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.1" /> 

, die eine schlechte Idee zu sein, stellte sich heraus, denn das war nun, dass Fehler werfen, ohne sie meine Migrationen laufen mit meinem Web-App als mein Start Projekt den Fehler zurück „Nicht Zusammenhang bla bla mit bla Namen blah gefunden“ so erkannte ich Kontexte, die ich schuf mich ohne Pannen gearbeitet, damit ich dies für PersistentGrantDBCOntext und COnfigurationGrantDbContext

tat
public class PGrantDbContext: PersistedGrantDbContext 
{ 
    public PGrantDbContext(DbContextOptions<PersistedGrantDbContext> options, OperationalStoreOptions storeOptions) : base(options, storeOptions) 
    { 

    } 
} 

und

public ConfigDbContext(DbContextOptions<ConfigurationDbContext> options, ConfigurationStoreOptions storeOptions):base(options,storeOptions) 
    { 

    } 

und alles lief reibungslos. Nur nicht so sicher, ob es der richtige Ansatz ist

+0

Ich habe das folgende Problem: Es wurde kein parameterloser Konstruktor auf 'PGrantDbContext' gefunden. Fügen Sie entweder einen parameterlosen Konstruktor zu 'PGrantDbContext' hinzu oder fügen Sie eine Implementierung von 'IDbContextFactory ' in derselben Assembly wie 'PGrantDbContext' hinzu. Wie hast du es gelöst? – CoffeeCode

0

Ich war auch in einer ähnlichen Situation vor ein paar Wochen und hier ist, wie ich es gelöst habe.

Sehr ähnlich wie bei Ihnen, ich habe zwei Projekte Company.Identity (.NETCoreApp) als meine Identität Projekt und Company.Identity.Data (.NETStandard 1.6) für Migrationen genannt. Ich verwende Company.Identity Project als Startprojekt für Migrationszwecke, da es in der gleichen Lösung wie mein Datenprojekt ist und ich die Lösung nicht mit einem anderen Projekt als Startup-Projekt für Migrationen durcheinander bringen wollte.

Ich folgte dem Tutorial in here.

Die CLI-Tool Referenz <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> ist in meiner Company.Identity.csproj Datei.

ich alle Schritte in dem obigen Tutorial mit der Ausnahme der folgenden Differenz

In ConfigureServices Methode in der Company.IdentityStartup Klasse, habe ich die migrationsAssembly zu Company.Identity.Data

var migrationsAssembly = "Company.Identity.Data"; 

Beachten Sie, dass Company.Identity Projekt hat bereits IdentityServer4.EntityFramework Nugget-Paket installiert. Dadurch konnte ich die Migration für PersistedGrantDbContext hinzufügen. Aber als ich versuchte, die Migration für ConfigurationDbContext auszuführen, gab es mir einen Buildfehler.Dies lag daran, dass die für PersistedGrantDbContext generierten Migrationen IdentityServer4.EntityFramework nuget-Paket erforderten. Also musste ich das in der Company.Identity.Data project

installieren Ich konnte Migrationen mit den folgenden Befehlen nach obigen Änderungen über die Eingabeaufforderung in meinem Projekt Company.Identity hinzufügen.

dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Migrations/IdentityServer/PersistedGrantDb -p ../Company.Identity.Data 

dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Migrations/IdentityServer/ConfigurationDb -p ../Company.Identity.Data 

Hoffnung, die

Verwandte Themen