DbContext Scaffold Error

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
dgxhubbard
Posts: 47
Joined: Fri 14 Aug 2015 20:58

DbContext Scaffold Error

Post by dgxhubbard » Thu 04 Oct 2018 21:54

From visual studio 2017 (15.8.1) create a .net core 2.1 console app.
Open NuGet Package Mgr and install
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Tools
Devart.Data.SQLite.EFCore
Devart.Data.SQLite.EFCore.Design

Now place a sqlite database in the project directory.
Open a command prompt that can run dotnet ef commands and use the following command:

dotnet ef dbcontext scaffold "DataSource=mydb.db3;" Devart.Data.SQLite.Entity.EFCore -o Model

For my database I get the error shown below. What is causing the error and what does the error mean.

Error Output

System.InvalidOperationException: Unexpected provider manifest token ''. Could not determine storage version; a valid version hint is required.
at .(String )
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at ..ctor(RelationalTypeMapperDependencies , )
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unexpected provider manifest token ''. Could not determine storage version; a valid version hint is required.

dgxhubbard
Posts: 47
Joined: Fri 14 Aug 2015 20:58

Re: DbContext Scaffold Error

Post by dgxhubbard » Thu 04 Oct 2018 22:01

The database was created using a script and sqlite command line:

sqlite Samp705.db3 < Samp705.sql

It does not seem I can attach the script to the post.

dgxhubbard
Posts: 47
Joined: Fri 14 Aug 2015 20:58

Re: DbContext Scaffold Error

Post by dgxhubbard » Thu 04 Oct 2018 22:16

Using verbose option:


C:\Repository\ConsoleApp1\ConsoleApp1>dotnet ef dbcontext scaffold "DataSource=Samp705.db3;" Devart.Data.SQLite.Entity.EFCore -o Model705 --verbose
Using project 'C:\Repository\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj'.
Using startup project 'C:\Repository\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj'.
Writing 'C:\Repository\ConsoleApp1\ConsoleApp1\obj\ConsoleApp1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\dgxhubbard\AppData\Local\Temp\tmpF862.tmp /verbosity:quiet /nologo C:\Repository\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj
Writing 'C:\Repository\ConsoleApp1\ConsoleApp1\obj\ConsoleApp1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\dgxhubbard\AppData\Local\Temp\tmpFA66.tmp /verbosity:quiet /nologo C:\Repository\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj
dotnet build C:\Repository\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj /verbosity:quiet /nologo

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.60
dotnet exec --depsfile C:\Repository\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1\ConsoleApp1.deps.json --additionalprobingpath C:\Users\dgxhubbard\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Repository\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1\ConsoleApp1.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.1.403\DotnetTools\dotnet-ef\2.1.4\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll" dbcontext scaffold DataSource=GtSamp705.db3; Devart.Data.SQLite.Entity.EFCore -o Model705 --assembly C:\Repository\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1\ConsoleApp1.dll --startup-assembly C:\Repository\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1\ConsoleApp1.dll --project-dir C:\Repository\ConsoleApp1\ConsoleApp1\ --language C# --working-dir C:\Repository\ConsoleApp1\ConsoleApp1 --verbose --root-namespace ConsoleApp1
Using assembly 'ConsoleApp1'.
Using startup assembly 'ConsoleApp1'.
Using application base 'C:\Repository\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1'.
Using working directory 'C:\Repository\ConsoleApp1\ConsoleApp1'.
Using root namespace 'ConsoleApp1'.
Using project directory 'C:\Repository\ConsoleApp1\ConsoleApp1\'.
Finding design-time services for provider 'Devart.Data.SQLite.Entity.EFCore'...
Using design-time services from provider 'Devart.Data.SQLite.Entity.EFCore'.
Finding design-time services referenced by assembly 'ConsoleApp1'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'ConsoleApp1'...
No design-time services were found.
System.InvalidOperationException: Unexpected provider manifest token ''. Could not determine storage version; a valid version hint is required.
at .(String )
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at ..ctor(RelationalTypeMapperDependencies , )
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unexpected provider manifest token ''. Could not determine storage version; a valid version hint is required.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: DbContext Scaffold Error

Post by Shalex » Thu 11 Oct 2018 18:21

Thank you for your report. We have reproduced the issue and are working on it. We will notify you when it is fixed.

As a workaround, please generate the code with Entity Developer (it comes with dotConnect for SQLite Professional installation): right click on your project in Solution Explorer > Add > New Item > ASP.NET Core > Devart EF Core Model.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: DbContext Scaffold Error

Post by Shalex » Thu 25 Oct 2018 16:57

The bug with using Scaffold-DbContext in EF Core 2 is fixed: viewtopic.php?f=29&t=37910.

Post Reply