ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.11k stars 292 forks source link

Method not found: IServiceCollection AddHandlebarsScaffolding #46

Closed miguelhughes closed 6 years ago

miguelhughes commented 6 years ago

Hi! Great tool, I use it daily for updating my model from db changes. It's the best one I've used so far. From some days ago, I'm unable to reverse engineer my db. I get the following exception when I try to do so:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.EntityFrameworkCore.Design.ServiceCollectionExtensions.AddHandlebarsScaffolding(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.EntityFrameworkCore.Design.ReverseEngineerOptions, System.ValueTuple`2<System.String,System.Action`3<System.IO.TextWriter,System.Object,System.Object[]>>[])'.
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 153

from the looks of it, it is similar to issue #35

Steps to reproduce

I guess the error started happening when I uninstalled another related tool, but to be honest, I really don't know, so I'm asking for help. This my guess of the steps that would cause it again:

  1. install https://github.com/ErikEJ/SqlCeToolbox
  2. install https://github.com/ErikEJ/EFCorePowerTools
  3. uninstall SqlCeToolbox
  4. right click on project
  5. select ef core power tools -> reverse engineer
  6. click ok in the next 3 modals until the model generation is triggered
  7. The exception is shown on the output window

First I used sqlcetoolbox for a few months. then I had to stop using it due to project requirements, so I went to using the old scaffold-dbcontext. After some months I came across efcorepowertools which made us very happy for some months. and now I'm having this issue. I hope I can go back to using it soon!

Further technical details

EF Core Power Tools version: Version 1.0.612.0

SQL Server Compact 4.0 in GAC - Yes - 4.0.8876.1 SQL Server Compact 4.0 DbProvider - Yes

SQL Server Compact 4.0 DDEX provider - No SQL Server Compact 4.0 Simple DDEX provider - Yes

SQLite ADO.NET Provider included: 1.0.107.0 SQLite EF6 DbProvider in GAC - No

System.Data.SQLite DDEX provider - No SQLite Simple DDEX provider - Yes

Database engine: SQL Server

Visual Studio version: Visual studio enterprise 2017 version 15.6.6

ErikEJ commented 6 years ago

Do you have Handlebars option selected?

ErikEJ commented 6 years ago

Have you tried build 613? Or the latest build on Marketplace? (Not daily)

ErikEJ commented 6 years ago

I have made som updates in the latest daily build - could you try that out?

miguelhughes commented 6 years ago

thanks for the quick responses!

Do you have Handlebars option selected?

I didn't. now I tried with and without, same error.

Have you tried build 613? Or the latest build on Marketplace?

I was up to date when I was having the issue (latest build). Then I switched to the daily build - same behavior

I have made som updates in the latest daily build - could you try that out?

thanks! trying now.

miguelhughes commented 6 years ago

Now I'm at version 1.0.614.0. I get the same error:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.EntityFrameworkCore.Design.ServiceCollectionExtensions.AddHandlebarsScaffolding(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.EntityFrameworkCore.Design.ReverseEngineerOptions, System.ValueTuple`2<System.String,System.Action`3<System.IO.TextWriter,System.Object,System.Object[]>>[])'.
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 153

I find it strange that the callstack is the same, with exact line numbers, but the about dialog confirms that I'm updated to 614.

I also tried deleting all the dlls of the output from my project, doing clean& rebuild of the solution, and even downloading my repo to a new location and trying there. This was to rule out any local problems related to the solution.

Is it possible this is some sort of GAC/dll problem? Are there any dlls I should look for and try to remove?

ErikEJ commented 6 years ago

@bricelam Any ideas?

miguelhughes commented 6 years ago

I'm tempted to install sqlcetoolbox back, but I don't want to break things further

ErikEJ commented 6 years ago

I think I know what is happening:

For some reason, Visual Studio loads an older version of the EntityFrameworkCore.Scaffolding.Handlebars.dll, that does not have a recent overload, but has the same AssemblyVersion (a pre-release dll).

1: Locate any instances of the EntityFrameworkCore.Scaffolding.Handlebars.dll file, and remove any older versions (would like to know if you find any, and where you find them)

2: A longer term solution is to ask the library author to increase the assembly version due to the "breaking" change. @tonysneed ??

tonysneed commented 6 years ago

I see. I can rev the assembly version and released the rev’d package. I’ll post here when done.

ErikEJ commented 6 years ago

@tonysneed Do you think my assumption sounds likely?

tonysneed commented 6 years ago

His call stack indicates that the Handlebars template source is included with the power tools source. Did you configure the power tools to use NuGet packages instead of source?

ErikEJ commented 6 years ago

Yes, not using source any longer

tonysneed commented 6 years ago

I can see that now .. I would like to know if he can find and remove any instances of the EntityFrameworkCore.Scaffolding.Handlebars.dll file. Nevertheless, it wouldn't hurt to rev the assembly version.

miguelhughes commented 6 years ago

The only one I could find is in AppData\Local\Microsoft\VisualStudio\15.0_d39a94c9\Extensions\dvazcsgy.aog which seems to be this extension itself. I backed it up and removed it, the error I get is:

File name: 'EntityFrameworkCore.Scaffolding.Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b10b51e7b9be6a2e'
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 153

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

I tried searching in the GAC, for what it's worth...

C:\>gacutil -l EntityFrameworkCore.Scaffolding.Handlebars
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:

Number of items = 0

now searching in c:

C:\>dir EntityFrameworkCore.Scaffolding.Handlebars.dll /s /p
 Volume in drive C has no label.
 Volume Serial Number is 4C18-6074
File Not Found

Some additional info, in case it matters: I'm using EntityframeworkCore 1.1.5 in my solution. I did have at one time have the nuget source "ASP.NET Core "dev" branch feed" (https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json) but I can't recall at the moment what it was for. Nevertheless it was disabled before I installed EFCorePowerTools.

ErikEJ commented 6 years ago

Your project is not related to this issue, it is a VS / EF Core Power Tools issue only.

I have no idea what is going on, TBH. Try removing the extension folder, restart VS and install EF Core Power Tools.

miguelhughes commented 6 years ago

Now we're back to :

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.EntityFrameworkCore.Design.ServiceCollectionExtensions.AddHandlebarsScaffolding(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.EntityFrameworkCore.Design.ReverseEngineerOptions, System.ValueTuple`2<System.String,System.Action`3<System.IO.TextWriter,System.Object,System.Object[]>>[])'.
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 154

Any other ideas? something else I should try?

ErikEJ commented 6 years ago

Try the latest daily build, a file was missing in build 616

miguelhughes commented 6 years ago

Thanks for your patience. I just tried the latest, regrettably the error is still the same:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.EntityFrameworkCore.Design.ServiceCollectionExtensions.AddHandlebarsScaffolding(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.EntityFrameworkCore.Design.ReverseEngineerOptions, System.ValueTuple`2<System.String,System.Action`3<System.IO.TextWriter,System.Object,System.Object[]>>[])'.
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 153

current version is 617.

I see the new file in the latest one - handlebars.dll, right?

ErikEJ commented 6 years ago

Yes, that was the missing file

Could you update Visual Studio to 15.7.3 or later?

miguelhughes commented 6 years ago

Updated to 15.7.3, got same error Uninstalled the extension, installed again 617; same error

What I don't understand is why my environment got so broken

ErikEJ commented 6 years ago

I have no idea - fusion log viewer, procmon etc are next steps

tonysneed commented 6 years ago

I’ll see if I can reproduce with the latest daily build.

ErikEJ commented 6 years ago

I have not been able to repro anything similar so far...

rsnider19 commented 6 years ago

I believe it is happening in EFCoreReverseEngineer:

if (reverseEngineerOptions.UseHandleBars)
{
    //TODO Consider being selective based on SelectedToBeGenerated
    serviceCollection.AddHandlebarsScaffolding();
    serviceCollection.AddSingleton<ITemplateFileService>(provider => new CustomTemplateFileService(reverseEngineerOptions.ProjectPath));
}

I am unable to run EFPT locally, but could it be that reverseEngineerOptions.UseHandleBars isn't coming correctly from the modal (and is always true), which triggers this code?

Also, I uninstalled/reinstalled Visual Studio and it is still not working for me.

tonysneed commented 6 years ago

I downloaded the daily build today (v 1.0.617) and installed it in Visual Studio Community 2017 (v 15.7.4). I used the DuplicateExtensionFinder to validate the install and observe that Handlebars.dll was located in the extension directory. Then I use the EF Core Power Tools to reverse engineer an existing database. The process completed without error.

However, when I attempted to add a DbContext model diagram, I received the following error:

System.ArgumentException: No EF Core DbContext types found in the project
   at ReverseEngineer20.EfCoreModelBuilder.GetDbContextTypes(DbContextOperations operations) in C:\Code\EFCorePowerTools\src\GUI\efpt\EFCoreModelBuilder.cs:line 76
   at ReverseEngineer20.EfCoreModelBuilder.BuildResult(String outputPath, Boolean generateDdl) in C:\Code\EFCorePowerTools\src\GUI\efpt\EFCoreModelBuilder.cs:line 34
   at ReverseEngineer20.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt\Program.cs:line 44

Parameter name: processResult
   at EFCorePowerTools.Handlers.ModelAnalyzerHandler.Generate(String outputPath, Project project, GenerationType generationType) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ModelAnalyzerHandler.cs:line 49

The same error occurred when executing any of the other DbContext related commands in EF Core Power Tools, even though a DbContext does indeed exist in the project.

ErikEJ commented 6 years ago

@tonysneed So you are also unable to reproduce the current issue!

Reverse engineering and Model inspection are two very distinct features in EF Core Power Tools.

RevEng runs in-process with VS, uses the Design bits from EF Core and simply drops files in the selected project.

Model inspection run of out process (via command line tools) and invokes the compiled dlls from the user project - so is much more brittle and complicated.

Model inspection requires a constructible and configured DbContext. If you continue to have issues with that feature, please raise a new issue.

tonysneed commented 6 years ago

I synced the package and assembly versions with release v1.1.1: https://www.nuget.org/packages/EntityFrameworkCore.Scaffolding.Handlebars/1.1.1

@ErikEJ If you use this version we should be able to validate the correct version.

ErikEJ commented 6 years ago

@rsnider19 @miguelhughes The latest daily build includes an update to the Handlebars library where then assembly version has been updated to higher than 1.0.0 - would be grateful if you could try it out.

ghost commented 6 years ago

I'm also having this same error message. Tried with the recent daily build. Still having the same error.

Question though, the error message seems to be referencing a directory that doesn't exist on my computer. Is that normal?

C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:

ErikEJ commented 6 years ago

How recent a build? Yes, that is normal...

ghost commented 6 years ago

The latest daily build.

ErikEJ commented 6 years ago

Sadly, I am unable to repro - so no clue what to do in order to release support for 2.1 other than remove handlebars support or get close to a machine/VM that exhibits this issue

ErikEJ commented 6 years ago

@rsnider19 @miguelhughes any status updates?

miguelhughes commented 6 years ago

In a desperate attempt I installed SqlCeToolbox, still same error I installed the daily build, with sqlcetoolbox in place - same error. Uninstalled both, installed daily build - same error.

I am working on a Parallels VM. would it help If I tried to upload a snapshot of it somewhere for you to take a look?

I guess my best shot is to uninstall & install visual studio again and apply the daily build?

ErikEJ commented 6 years ago

@miguelhughes

I guess my best shot is to uninstall & install visual studio again and apply the daily build?

That should not be required. Have you checked for duplicate extensions ? https://github.com/remcoros/DuplicateExtensionFinder

I am working on a Parallels VM. would it help If I tried to upload a snapshot of it somewhere for you to take a look?

A VM sounds great - can I run a parallels VM on Windows?

miguelhughes commented 6 years ago

I just need to get this working again. Any suggestions?

I tried duplicate extension finder. there are a couple there (appinsights, azure) but none related to your tools. should I fix those errors anyway?

A VM sounds great - can I run a parallels VM on Windows?

It doesn't look like there's an easy one for that, i've googled it a bit. But If you're willing to give it a shot I can upload it somewhere for you.

Perhaps some of the other users having this are an easier option...

ErikEJ commented 6 years ago

I just need to get this working again. Any suggestions?

Let me try to completly remove/disable handlebars from a daily build - will let you know when I have done so

tonysneed commented 6 years ago

In case you guys want to use an VM in Azure with VS 2017 community: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/using-visual-studio-vm.

tonysneed commented 6 years ago

However, this sounds like it's specific to the setup for @miguelhughes. Here is what I would suggest to troubleshoot:

That should help us diagnose the issue with regard to the missing method exception.

rsnider19 commented 6 years ago

Still not working for me. DuplicateFileFinder is clean, and here is my dotPeek: image

Also, I am on VS2017 Community if that helps.

ErikEJ commented 6 years ago

I am clueless atm, will try a daily build with no Handlebars support soon

tonysneed commented 6 years ago

@ErikEJ Is anything installed to the GAC? And does EFC PT use package or assembly references?

ErikEJ commented 6 years ago

Packages.config = assembly references, and nothing in GAC

tonysneed commented 6 years ago

I'm wondering if somehow there are multiple installations of the extension (although DuplicateExtensionFinder would flag those). @miguelhughes Can you check the version of ECF PT that is in the installation folder you're inspecting, versus the version that is in the about box in VS? @ErikEJ What version(s) of the extension has the v1.1.1 dependency on my extension?

kachalkov commented 6 years ago

We have the same issue, what we don't understand is how issue is still happening if we not select to use handlebar templates?

We have it working fine on laptop, but fails on virtual machine and it looks like related to handler service for custom one...

ErikEJ commented 6 years ago

I have attached a preview build with Handlebars disabled here, for you all to try out.

EFCorePowerTools.1.0.623.vsix.zip

tonysneed commented 6 years ago

Since a lot of folks are having this issue, perhaps I can remove the overload of the extension method and instead create a separate extension method for adding Handlebars helpers.

ErikEJ commented 6 years ago

I have been thinking the same, maybe you could bring back a plain extension method..

tonysneed commented 6 years ago

I’ll get that done today and publish a new version.

rsnider19 commented 6 years ago

Success!!! 623 work for me now!!