Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when using Reverse Engineering with Handlebars #463

Closed
hanselsen opened this issue Aug 14, 2020 · 27 comments
Closed
Labels
bug Something isn't working

Comments

@hanselsen
Copy link

I have this configuration and I already have the CodeTemplates folder in my project.

image

Using VS2019, MySQL 8 and EFCorePowerTools 2.4

And I get this result:

System.Exception: Reverse engineer error: 
System.NullReferenceException: Object reference not set to an instance of an object.
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateRelationship(IForeignKey foreignKey, Boolean useDataAnnotations, IndentedStringBuilder sb)
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateEntityType(IEntityType entityType, Boolean useDataAnnotations, IndentedStringBuilder sb)
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateOnModelCreating(IModel model, Boolean useDataAnnotations)
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateClass(IModel model, String contextName, String connectionString, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.WriteCode(IModel model, String contextName, String connectionString, String contextNamespace, String modelNamespace, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at ReverseEngineer20.ReverseEngineer.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions reverseEngineerOptions) in C:\Code\EFCorePowerTools\src\GUI\RevEng.Core\ReverseEngineerRunner.cs:line 89
   at efreveng.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efreveng\Program.cs:line 57

   at EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult(String output) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\ResultDeserializer.cs:line 27
   at ReverseEngineer20.ReverseEngineer.EfRevEngLauncher.GetOutput() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\EfRevEngLauncher.cs:line 81
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.LaunchExternalRunner(ReverseEngineerOptions options, Boolean useEFCore5) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 381
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__3.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 225

Any ideas?

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 14, 2020

Maybe #450 ?

@hanselsen
Copy link
Author

I removed the CodeTemplates folder from the File Explorer and ran the generator again. Still returns the same error.

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 14, 2020

No idea - let's ask @tonysneed

@tonysneed
Copy link
Contributor

Let me check.

@tonysneed
Copy link
Contributor

I have not been able to replicate the error. Here is the version of EFCPT I am using: 2.4.157.0

I have reverse engineered both SQL Server and MySQL databases, checking the option to Customize Code using Handlebars templates. In both cases there were no errors at all.

@hanselsen What is the exact version of EFCPT you are using?

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 14, 2020

We probably need your schema!

@hanselsen
Copy link
Author

Is there a way I can send it to you privately?

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 15, 2020

Sure, email me ejlskov at Hotmail dot com

@hanselsen
Copy link
Author

@tonysneed I also use 2.4.157. I mailed @ErikEJ my schema.

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 15, 2020

@hanselsen I just realize you are using MySQL - most likely an issue with your provider - are you using Pomelo?

@hanselsen
Copy link
Author

Yes. It's Pomelo 3.2.1

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 17, 2020

@hanselsen Look like a Handlebars bug - see TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars#136

@ErikEJ ErikEJ added the bug Something isn't working label Aug 18, 2020
@ErikEJ ErikEJ closed this as completed in 5961c41 Aug 18, 2020
@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

Should be fixed in latest daily build, please try it out and let me know.

@hanselsen
Copy link
Author

I now have version 2.4.163, but it is still showing the same NRE.
I did delete the CodeTemplates folder from the disk again.

@ErikEJ ErikEJ reopened this Aug 18, 2020
@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

I think you need to verify the bug, using Handlebars from the command line as described here: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars#usage and if you are able to do so, file a bug in the Handlebars repo.

@hanselsen
Copy link
Author

Alright. Updating the Handlebars package to 3.8.3 did the trick.
Thanks for the support! 👌

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

@hanselsen I do not understand - the latest Power Tools build also uses 3.8.3 !?

@hanselsen
Copy link
Author

Could it be that it used the installed Nuget package (so, old) instead of the package that is bundled with Power Tools?

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

What is installed in your project and by Power Tools are two completely different things! Power Tools does not run your app.

@hanselsen
Copy link
Author

I would think so, but after updating the Nuget package to 3.8.3, it worked...

@hanselsen
Copy link
Author

Right now, I have

Version 2.4.163.0

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

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

But it stopped working again... this is getting frustrating.
Is there a way for me to debug it myself?

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

Maybe you still have the old version of the extension hanging around,
shut down and restart any VS instances and check %localappdata%\Microsoft\VisualStudio folder (and subfolders)

@hanselsen
Copy link
Author

I cleared the cache. Reinstalled the Power Tools and still the NRE.
I also tried it using the CLI as instructed here https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars#usage and that works. Also the template files.

In combination with the Power Tools however, nothing.

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

I could have made a mistake when I merged - will rebuild the tooling a prep a newer Power Tools build

ErikEJ added a commit that referenced this issue Aug 18, 2020
@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

Update on the way! (Build .164 or newer)

@ErikEJ
Copy link
Owner

ErikEJ commented Aug 18, 2020

Once installed, you can locate EntityFrameworkCore.Scaffolding.Handlebars.dll and verify the Product version from File Properties

@hanselsen
Copy link
Author

Awesome! It works. Thanks for the great tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants