NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
124 stars 24 forks source link

Rendering failed: Sequence contains no elements #2

Closed RudeySH closed 3 years ago

RudeySH commented 3 years ago

Thanks for creating NTypewriter! I'm currently attempting to replace Typewriter with something else, this project looks very promising.

Currently, NTypewriter appears to be working for me (it generates files), but after rendering the example template from the readme in my project, Visual Studio's status bar says "Rendering failed" and the following exception/stacktrace is logged:

ERROR: System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager.GetAssociatedProjectItems(String projectFilePath, String id) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager..ctor(DTE2 dte, String templateFilePath, String projectFilePath) at NTypewriter.EditorForVisualStudio.NTypewriterEditorForVisualStudioPackage.<>cDisplayClass11_0.b2() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at NTypewriter.EditorForVisualStudio.NTypewriterEditorForVisualStudioPackage.d__11.MoveNext()

NeVeSpl commented 3 years ago

Could you upload a sample project on which this error can be reproduced on GitHub?

RudeySH commented 3 years ago

I created a new project using the built-in "Class Library (.NET Framework)" Visual Studio template. This uses .NET Framework 4.8 and the legacy project system. (As you already noted, #3 might be related.) Then I added a Template.nt using the first example from the readme. Lastly I added a dummy ClassModel.cs.

https://github.com/RudeySH/NTypewriterSampleClassLibrary

This gives me a different exception than before:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) at EnvDTE.Properties.Item(Object index) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager.GetId(ProjectItem item) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager.<>cDisplayClass9_0.b1(ProjectItem x) at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager.GetAssociatedProjectItems(String projectFilePath, String id) at NTypewriter.EditorForVisualStudio.Editor.SolutionItemsManager..ctor(DTE2 dte, String templateFilePath, String projectFilePath) at NTypewriter.EditorForVisualStudio.NTypewriterEditorForVisualStudioPackage.<>cDisplayClass11_0.b__2() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at NTypewriter.EditorForVisualStudio.NTypewriterEditorForVisualStudioPackage.d11.MoveNext()

Removing ClassModel.cs gives me a different exception, much more similar to the original exception I had, but not quite the same:

System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.Max(IEnumerable`1 source) at NTypewriter.EditorForVisualStudio.NTypewriterEditorForVisualStudioPackage.d__11.MoveNext()

NeVeSpl commented 3 years ago

Second and third exceptions are corrected in v0.0.3, but I am still not able to reproduce the first one.

RudeySH commented 3 years ago

Now that the other exceptions are fixed, I was able to reproduce the original exception in a new project. Adding a solution folder causes the exception. I have updated the sample repository: https://github.com/RudeySH/NTypewriterSampleClassLibrary

NeVeSpl commented 3 years ago

Fixed in v0.0.4

RudeySH commented 3 years ago

Thanks! I noticed no new commits in this repository, is the NTypewriter extension not part of this codebase?

NeVeSpl commented 3 years ago

Indeed, NTypewriter editor for Visual Studio has a separate private repository. It is not ready to go public.