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

Large designer files crash converter (within VS) during formatting #778

Closed
KunzeAndreas opened this issue Oct 21, 2021 · 9 comments
Closed

Comments

@KunzeAndreas
Copy link

Steps to reproduce

  1. convert solution
  2. crash in phase 1 of 2 converting forms

Error message shown

  • Office\COGuiCommon\IdentArtikel\IdentArtikelForm.Designer.vb - conversion started
  • Office\COGuiCommon\Tourenplan\TourenplanForm.Designer.vb - conversion succeeded
  • Office\COGuiCommon\Vertraege\VertragsMaschinenHinzufuegen\VertragsMaschinenHinzufuegenForm.Designer.vb - conversion started

Error while formatting and converting comments: System.InvalidOperationException: Exception of type 'System.InvalidOperationException' was thrown.

Error while formatting and converting comments: System.InvalidOperationException: Exception of type 'System.InvalidOperationException' was thrown.
at System.Runtime.CompilerServices.ConditionalWeakTable2.VerifyIntegrity() at System.Runtime.CompilerServices.ConditionalWeakTable2.TryGetValue(TKey key, TValue& value)
at Microsoft.CodeAnalysis.GreenNode.GetAnnotations()
at Microsoft.CodeAnalysis.GreenNode.HasAnnotation(SyntaxAnnotation annotation)
at Microsoft.CodeAnalysis.CSharp.Formatting.TriviaDataFactory.Analyzer.AnalyzeWhitespacesInTrivia(SyntaxTrivia trivia, AnalysisResult& result)
at Microsoft.CodeAnalysis.CSharp.Formatting.TriviaDataFactory.Analyzer.Analyze(SyntaxTriviaList list, AnalysisResult& result)
at Microsoft.CodeAnalysis.CSharp.Formatting.TriviaDataFactory.Analyzer.Leading(SyntaxToken token)
at Microsoft.CodeAnalysis.CSharp.Formatting.TriviaDataFactory.CreateLeadingTrivia(SyntaxToken token)
at Microsoft.CodeAnalysis.Formatting.TokenStream.GetOriginalTriviaData(TokenData token1, TokenData token2)
at Microsoft.CodeAnalysis.Formatting.TokenStream.GetColumn(TokenData tokenData, Func3 triviaDataGetter) at Microsoft.CodeAnalysis.Formatting.FormattingContext.AddAnchorIndentationOperation(AnchorIndentationOperation operation) at Roslyn.Utilities.EnumerableExtensions.Do[T](IEnumerable1 source, Action1 action) at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.Format(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CSharp.Formatting.CSharpSyntaxFormattingService.Format(SyntaxNode node, AnalyzerConfigOptions options, IEnumerable1 formattingRules, SyntaxToken token1, SyntaxToken token2, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Formatting.AbstractSyntaxFormattingService.FormatIndividually(SyntaxNode node, AnalyzerConfigOptions options, IEnumerable1 rules, IList1 spansToFormat, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Formatting.AbstractSyntaxFormattingService.Format(SyntaxNode node, IEnumerable1 spans, Boolean shouldUseFormattingSpanCollapse, AnalyzerConfigOptions options, IEnumerable1 rules, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Formatting.Formatter.GetFormattingResult(SyntaxNode node, IEnumerable1 spans, Workspace workspace, OptionSet options, IEnumerable1 rules, CancellationToken cancellationToken)
at ICSharpCode.CodeConverter.Shared.OptionalOperations.Format(SyntaxNode node, Document document)
at ICSharpCode.CodeConverter.Shared.OptionalOperations.MapSourceTriviaToTargetHandled[TSource,TTarget](TSource root, TTarget converted, Document document)

Details

  • Product in use: e.g. VS extension
  • Version in use: 8.4.1.0
  • Did you see it working in a previous version, which? no
@GrahamTheCoder
Copy link
Member

Is VertragsMaschinenHinzufuegenForm.Designer.vb a very large file and fails after a couple of minutes by any chance?
The roslyn formatter (while hosted in 32 bit visual studio) struggles to format such files without running out of memory and getting stuck. Under Code Converter in Tools, Options, there's an timeout you can set to make it skip after a certain amount of time which may help work around this for now.
You could also try running it in VS2022 or via the command line.
I'll investigate the issue and see if I can avoid it breaking the whole conversion by catching it and returning the unformatted version.

@KunzeAndreas
Copy link
Author

Thank you for the fast answer.

VertragsMaschinenHinzufuegenForm is not large, but we have some other real big form designer files (>10.000 lines of code), may be, this is the root problem. Conversation fails after some hours with 'out of memory'.

I'll use a shorter timeout (default is 600 minutes) and try to run conversation from command line (how can I start conversation from command line?)

@GrahamTheCoder
Copy link
Member

For command line, start with dotnet tool install ICSharpCode.CodeConverter.codeconv --global
Then the help on it should be enough to go on from there

@KunzeAndreas
Copy link
Author

Now the converter crashes in VS 2019 and also in VS 2022 without message.
/Log command doesn't help (no XML files found).
Trying to split failing project to convert in smaller pieces...

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Oct 29, 2021

Oh dear, especially sad to hear it crashes Vs2022! I still believe big files are likely the cause. So even taking the longest files and just splitting them in half using partial classes can work. Especially designer files which end up much larger after conversion usually.

@KunzeAndreas
Copy link
Author

After splitting crashing assembly it works

@GrahamTheCoder
Copy link
Member

Thanks for letting me know, glad it's working.

I think the outcome here is that I (or indeed anyone) should try to reproduce this bug using just the roslyn API here and submit it as an issue upstream:

// This call is very expensive for large documents. Should look for a more performant version, e.g. Is NormalizeWhitespace good enough?
return Formatter.Format(node, document.Project.Solution.Workspace, cancellationToken: token);

I did previously (separately) log the bug upstream of the fact that VS intentionally hard crashes when various things go wrong:
dotnet/roslyn#41724
At that time I had a workaround, to avoid the hard crahses, but it may need a rework after their improvements in dotnet/roslyn#48367

@GrahamTheCoder GrahamTheCoder changed the title Converter crashes Large designer files crash converter (within VS) during formatting Dec 11, 2021
@GrahamTheCoder
Copy link
Member

In #774 I've made a change to decrease the amount of boilerplate for events in many common cases. Hopefully this will help mitigate the issue until a fix can be found

@GrahamTheCoder
Copy link
Member

Ah whoops I've left a duplicate of this. Consolidating this into #877

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants