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

NPE in Razor template List called without DB #1773

Open
yecril71pl opened this issue Dec 31, 2021 · 0 comments · May be fixed by #1774
Open

NPE in Razor template List called without DB #1773

yecril71pl opened this issue Dec 31, 2021 · 0 comments · May be fixed by #1774

Comments

@yecril71pl
Copy link
Contributor

yecril71pl commented Dec 31, 2021

File a bug

When there is no database context defined and the selected template is List, the Razor generator fails with a null pointer exception in unknown code.

Include your code

Dictionary<string, IPropertyMetadata>
 propertyLookup
 = ((IModelMetadata)Model.ModelMetadata).Properties.ToDictionary(x => x.PropertyName, x => x);

Include stack traces

Note: source heavily modified, line numbers do not match. It took me 3w to pull this thing apart and put it back together in a somewhat useful form (including to get any stack trace at all).

fail: Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand[813862114]
      Code generation failed!
      System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
       ---> System.NullReferenceException: Object reference not set to an instance of an object.
         at Razor.Template.ExecuteAsync()
         at Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase.ExecuteTemplate() in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Templating/RazorTemplateBase.cs:line 36
         at Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplating.RunTemplateAsync(String content, Object templateModel) in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Templating/RazorTemplating.cs:line 158
         at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorActionsService.AddFileFromTemplateAsync(String outputPath, String templateName, IEnumerable`1 templateFolders, Object templateModel) in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Core/CodeGeneratorActionsService.cs:line 118
         at Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Razor.RazorPageScaffolderBase.GenerateView(RazorPageGeneratorModel razorGeneratorModel, ModelTypeAndContextModel modelTypeAndContextModel, String outputPath) in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Mvc/RazorPage/RazorPageScaffolderBase.cs:line 269
         at Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Razor.EmptyRazorPageScaffolder.GenerateCode(RazorPageGeneratorModel razorGeneratorModel) in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Mvc/RazorPage/EmptyRazorPageScaffolder.cs:line 58
         at Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Razor.RazorPageGenerator.GenerateCode(RazorPageGeneratorModel razorPageGeneratorModel) in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Mvc/RazorPage/RazorPageGenerator.cs:line 74
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
         at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
         at System.Threading.Tasks.Task.Wait()
         at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__8_0() in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Core/ActionInvoker.cs:line 105
         at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) in /home/dell/.nuget/packages/microsoft.extensions.commandlineutils.sources/6.0.0-preview.3.21166.3/contentFiles/cs/netstandard1.0/CommandLine/CommandLineApplication.cs:line 374
         at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute() in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG.Core/ActionInvoker.cs:line 54
         at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute() in /home/dell/prog/Scaffolding/src/Scaffolding/VS.Web.CG/CodeGenCommand.cs:line 93

Include provider and version information

Microsoft.VisualStudio.Web.CodeGeneration.Design/Microsoft.DotNet.MSIdentity version:
1.0.0
Target framework: (e.g. .NET 5.0)
6.0.1
Operating system:
Linux x64 5.15.8-1-default
IDE: (e.g. Visual Studio 2019 16.3)
1.63.2
yecril71pl added a commit to yecril71pl/Scaffolding that referenced this issue Dec 31, 2021
The List template throws ArgumentNullException on null model metadata.
Fixes dotnet#1773.
@yecril71pl yecril71pl linked a pull request Dec 31, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant