Efcore: System.MissingMethodException: Method not found: 'Void Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseTable..ctor(Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseModel, System.String)'.

Created on 11 Sep 2020  路  37Comments  路  Source: dotnet/efcore

Below is the complete stack trace of the error I receive when using following scaffold command. What could be wrong?

I am using Npgsql Postgres code, changed for my database as far as internal SQLs are concerned, as such no change in logic flow. Changed GetTables() method code is pasted below for reference, it calls "DatabaseTable()" which results into "System.MissingMethodException" exception.

..\Scaffolding\Internal\NpgsqlDatabaseModelFactory.cs

    /// <summary>
    /// Queries the database for defined tables and registers them with the model.
    /// </summary>
    static IEnumerable<DatabaseTable> GetTables(
        IfxConnection connection,
        DatabaseModel databaseModel,
        IDiagnosticsLogger<DbLoggerCategory.Scaffolding> logger)
    {
        var commandText = @"
        SELECT
           owner, tabname
        FROM
           informix.sysmaster:systables
        WHERE
           tabid > 99;";

        var tables = new List<DatabaseTable>();

        var command = new IfxCommand(commandText, connection);
        using (var reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                var schema = reader.GetValueOrDefault<string>("owner");
                var name = reader.GetString("tabname");

                var table = new DatabaseTable(databaseModel, name)
                {
                    Schema = schema,
                };

                tables.Add(table);
            }
        }

        GetColumns(connection, tables, logger);
        GetConstraints(connection, tables, out var constraintIndexes, logger);
        GetIndexes(connection, tables, constraintIndexes, logger);
        return tables;
    }

D:\shesh\EntityFrameworkCore\scaffold>dotnet ef dbcontext scaffold "Database=sheshefcoredb1; server=lo_informix1410;UID=informix; PWD=xxx" Informix.EntityFramework.Core -o Models --project MyApp.csproj -v
Using project 'MyApp.csproj'.
Using startup project 'D:\shesh\EntityFrameworkCore\scaffold\MyApp.csproj'.
Writing 'obj\MyApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\sheshnarayan.a\AppData\Local\Temp\tmpE5DF.tmp /verbosity:quiet /nologo MyApp.csproj
Writing 'D:\shesh\EntityFrameworkCore\scaffold\obj\MyApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\sheshnarayan.a\AppData\Local\Temp\tmpEA65.tmp /verbosity:quiet /nologo D:\shesh\EntityFrameworkCore\scaffold\MyApp.csproj
Build started...
dotnet build D:\shesh\EntityFrameworkCore\scaffold\MyApp.csproj /verbosity:quiet /nologo

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

Time Elapsed 00:00:01.46
Build succeeded.
dotnet exec --depsfile D:\shesh\EntityFrameworkCore\scaffold\bin\x64\Debug\netcoreapp3.1\MyApp.deps.json --additionalprobingpath C:\Users\sheshnarayan.a.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\shesh\EntityFrameworkCore\scaffold\bin\x64\Debug\netcoreapp3.1\MyApp.runtimeconfig.json C:\Users\sheshnarayan.a.dotnet\tools.store\dotnet-ef\3.1.5\dotnet-ef\3.1.5\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll dbcontext scaffold "Database=sheshefcoredb1; server=lo_informix1410;UID=informix; PWD=xxx" Informix.EntityFramework.Core -o Models --assembly D:\shesh\EntityFrameworkCore\scaffold\bin\x64\Debug\netcoreapp3.1\MyApp.dll --startup-assembly D:\shesh\EntityFrameworkCore\scaffold\bin\x64\Debug\netcoreapp3.1\MyApp.dll --project-dir D:\shesh\EntityFrameworkCore\scaffold\ --language C# --working-dir D:\shesh\EntityFrameworkCore\scaffold --verbose --root-namespace MyApp
Using assembly 'MyApp'.
Using startup assembly 'MyApp'.
Using application base 'D:\shesh\EntityFrameworkCore\scaffold\bin\x64\Debug\netcoreapp3.1'.
Using working directory 'D:\shesh\EntityFrameworkCore\scaffold'.
Using root namespace 'MyApp'.
Using project directory 'D:\shesh\EntityFrameworkCore\scaffold\'.
The EF Core tools version '3.1.5' is older than that of the runtime '5.0.0-preview.5.20278.2'. Update the tools for the latest features and bug fixes.
Finding design-time services for provider 'Informix.EntityFramework.Core'...
Using design-time services from provider 'Informix.EntityFramework.Core'.
Finding design-time services referenced by assembly 'MyApp'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'MyApp'...
No design-time services were found.
System.MissingMethodException: Method not found: 'Void Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseTable..ctor(Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseModel, System.String)'.
at Informix.EntityFramework.Core.Scaffolding.Internal.NpgsqlDatabaseModelFactory.GetTables(IfxConnection connection, DatabaseModel databaseModel, IDiagnosticsLogger1 logger) at Informix.EntityFramework.Core.Scaffolding.Internal.NpgsqlDatabaseModelFactory.Create(DbConnection dbConnection, DatabaseModelFactoryOptions options) in D:\shesh\EntityFrameworkCore\efcore.pg-dev-ifmx-old\src\EFCore.Informix\Scaffolding\Internal\NpgsqlDatabaseModelFactory.cs:line 124 at Informix.EntityFramework.Core.Scaffolding.Internal.NpgsqlDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options) in D:\shesh\EntityFrameworkCore\efcore.pg-dev-ifmx-old\src\EFCore.Informix\Scaffolding\Internal\NpgsqlDatabaseModelFactory.cs:line 90 at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions) at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method not found: 'Void Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseTable..ctor(Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseModel, System.String)'.

D:\shesh\EntityFrameworkCore\scaffold>

closed-question customer-reported

Most helpful comment

You should never base a new provider on EF Core previews - ask me how I know 馃槶

All 37 comments

You have mixed versions of packages.

Thanks @smitpatel for pointers. Unfortunately, I am not able to figure out the version differences as other aspect of my EF Core Provider works correctly. I am attaching the project file which I am using. .NET SDK version is 3.1.401. Would be able to point the exact differences and what would be correct versions?

Thanks in advance.

MyApp.csproj.txt

The file you shared does not tell what versions Informix.EntityFramework.Core brings in.

@smitpatel , Kindly find the project file which builds Informix.EntityFramework.Core.dll and also global.json file.

EFCore.Informix.csproj.txt
global.json.txt

EFCore.Informix.csproj does not contain the versions of EF Core packages (see the <PackageReference> elements). They may be somewhere else, e.g. in a Directory.Build.targets at the root (assuming you followed EFCore.PG).

Attaching Directory.Build*, it has references to PackageReferences ...

Directory.Build.targets.txt
Directory.Build.props.txt

Your Directory.Build.targets file brings in different version of EFCore packages than MyApp project.
Preview versions do have breaking changes in between them and you _must_ use same package version for all the EF Core packages in all the projects in your solution.

@smitpatel , Thanks for the info. I tried to use following versions in the respective Build files to build my EF Core Provider DLL but I get thousands of errors (ofcourse the files I attached in previous post works but it seems that's not the correct version to be used). Could you please help to suggest the correct version for below parameters? I intend to use EF Core SDK 3.1.401 version.

Directory.Build.targets

<EFCoreVersion>3.1.401</EFCoreVersion>
<MicrosoftExtensionsVersion>3.1.401</MicrosoftExtensionsVersion>

Directory.Build.props

<VersionPrefix>3.1</VersionPrefix>

@deokershesh 3.1.401 is the version of the .NET Core SDK (downloadable via https://dotnet.microsoft.com) - this has nothing to do with EF Core. The version of SDK used is determined by your global.json, but in any case any 3.1 SDK should be fine for building your provider - it is most probably not the source of any issues you have.

EF Core is distributed via nugets (e.g. Microsoft.EntityFrameworkCore) which are referenced via <PackageReference> nodes in your csproj. The latest released version is 3.1.8 (note that version difference from the SDK, which is 3.1.401).

I suggest you take some time to familiarize yourself with how .NET projects build, how package management works, etc.

In continue attempt to resolve the issue, I made following changes in respective files (picked from Npgsql EF Core code link).

Directory.Build.targets

<EFCoreVersion>5.0.0-rc.1.20426.3</EFCoreVersion>
<MicrosoftExtensionsVersion>5.0.0-rc.1.20425.18</MicrosoftExtensionsVersion>

Directory.Build.props:
5.0.0-rc1

global.json:

{
"sdk": {
"version": "3.1.401",
"rollForward": "major",
"allowPrerelease": "false"
}
}

However the above reports "Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies."

From the Visual Studio 2019 Package Manager Console, installed "Microsoft.CodeAnalysis" as follows,

" Install-Package Microsoft.CodeAnalysis -Version 3.7.0.0"

Restarted Visual Studio 2019 (on the safe side) but still problem continues...

Thanks @roji , Will try to follow your latest post above...

From the Visual Studio 2019 Package Manager Console, installed "Microsoft.CodeAnalysis" as follows,

You should probably not need to take a direct dependency on this package - this error most probably indicates some other build/dependency issue in your project.

However, in general, it's practically impossible for us to help you out with partial fragments of project build files. You're going to have to either share your project (or at least its build files), or manage yourself. Once again, we really encourage you to look at the PostgreSQL provider - it builds just fine, and your provider should be able to do so as well. Compare the two to find the differences.

Thanks @roji , Yes, I picked the entire code repository from Npgsql PostgresSQL provider and it was/is working fine (project and other files attached in previous post. Attaching again), until I found this issue (#22492), which suggested version of "PackageReference" needs correction. I would be more than happy to share any more files/info would be needed to resolve the issue. As I understand, its possibly just the version change, it would be really great if I could be suggested to try few "exact version" values to fix the issue.

Thanks for your continued support and help.

Application Project file: With this project file, the issue reported occurs when I run "scaffold" command. Mentioned in first post.

MyApp.csproj.txt

EF Core Provider Project and other build files: These files are used to successfully build the EF Core Provider for my database.

Directory.Build.props.txt
Directory.Build.targets.txt
global.json.txt
EFCore.Informix.csproj.txt

.NET Core SDK/Runtime version used : 3.1.401

@deokershesh - At this point, either you would need to figure out your version conflicts yourself or share whole project with us. With bits and piece of random versions used everywhere, we cannot solve you problem and it only wastes time of everyone involved. We want to help you but this way is really ineffective at achieving anything.

@smitpatel , I understand, please let me know how do I share my entire project? Shall I attach here in .zip format?

Best way would be create a github repository and share the link of repository here.

Unfortunately I can't do the same yet due to other factors! Not sure if there is any restriction to upload here in size(I will remove built binaries before I upload) or format (.zip).

Since this is a scaffolding issue, what version of the EF tools do you have installed (dotnet-ef)? Execute dotnet tool list -g to find out.

I'm also noticing that your MyApp csproj above references versions preview3 versions of Microsoft.Extensions.Logging (and the other Microsoft.Extensions), but your provider references version preview2... Please go over everything - the provider, the program and the EF tools, and make sure everything aligns.

D:\shesh\EntityFrameworkCore\scaffold>dotnet tool list -g

Package Id Version Commands

dotnet-ef 3.1.5 dotnet-ef

D:\shesh\EntityFrameworkCore\scaffold>

Shall I change provider references to preview3, like same as MyApp project reference version?

I built Provider by using preview3 version(below) but still scaffolding issue remains same.

Directory.Build.targets file:
5.0.0-preview.3.20215.2

Please let me know, what else I could try to fix the issue.

Will appreciate any pointers to resolve the issue. At this moment, I am not sure what am I missing with respect to PackageReference version or any EF, SDK/Runtime version related issues. I would be more than happy to provide more info as needed.

@deokershesh we are currently very busy with other issues we have to give our attention to, wrapping up the EF Core 5.0 release.

Please try to compare your provider's configuration with the working one from EFCore.PG, you should be able to spot the discrepancy yourself. Otherwise, one of us will hopefully get around to helping soon.

Thanks @roji , I did compare with EFCore.PG, infact it uses preview-5, which it seems to have breaking changes. Will continue to try to investigate from my end, while EF Core 5.0 release work is done.

You should never base a new provider on EF Core previews - ask me how I know 馃槶

Now is a good time to switch to rc1. It's extremely unlikely that there will be any breaking changes from now until the GA release.

I did compare with EFCore.PG, infact it uses preview-5

FYI EFCore.PG has moved forward to rc1 since you looked at it. It could be a good idea for you to do the same.

@roji , I did try to use the rc1 version as follows, but it reports error during the EF Core Provider build,

"1>CSC : error CS8032: An instance of analyzer Microsoft.EntityFrameworkCore.InternalUsageDiagnosticAnalyzer cannot be created from C:\Users\sheshnarayan.a.nuget\packages\microsoft.entityframeworkcore.analyzers\5.0.0-rc.1.20451.13\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.."

Directory.Build.targets:
5.0.0-rc.1.20451.13
5.0.0-rc.1.20451.14

Directory.Build.props:
5.0.0-rc1

@deokershesh that's another instance of your build or dependency versions somehow being messed up. Fully match what EFCore.PG is doing and it will work.

@roji , I downloaded the latest code from https://github.com/npgsql/efcore.pg , and did fresh build with the new code and still get the exact same error. I have been struggling to resolve the dependencies only since sometime. It would be really great, if I could be pointed out with the exact issue, I can wait until EF Core 5 work is done. I can also try any other suggestions....

1>CSC : error CS8032: An instance of analyzer Microsoft.EntityFrameworkCore.InternalUsageDiagnosticAnalyzer cannot be created from C:\Users\sheshnarayan.a.nuget\packages\microsoft.entityframeworkcore.analyzers\5.0.0-rc.1.20451.13\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

@deokershesh since EFCore.PG is working well, that means you're introducing some issue yourself. I'm sorry, but we simply don't have the time to help you with these build issues, not in the near future in any case. Try to methodically narrow down what changes you've made from EFCore.PG until you find the issue.

@roji , I didn't make any code changes at all in the EFCore.PG repository. I simply downloaded (status says 968 commits) from repository https://github.com/npgsql/efcore.pg, opened "EFCore.PG.sln" in VS 2019 and did build. It reported above error. I really want to know, what possibly could be wrong in the environment without making any changes in the code, it reports build error!

Opened issue in Npgsql repository as well... https://github.com/npgsql/efcore.pg/issues/1507

@deokershesh I've answered you on that issue. EFCore.PG builds fine for me (and others).

I am experiencing these build warning issues as well with EF Core v5.0.0 in VS2019.

@fenton-nick the above was related to a custom provider copying code from EF Core. If you're seeing build issues with EF Core itself on v5.0.0 GA, can you please open a new issue with the full details, including all warnings/errors etc.?

@roji thanks. Issue created: 23534

Was this page helpful?
0 / 5 - 0 ratings