cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 119 forks source link

Visual Studio exception #136

Closed NoahStahl closed 3 years ago

NoahStahl commented 3 years ago

Thanks for this fantastic tool. It's been working well, but I've noticed this issue where Visual Studio periodically encounters an error, which upon inspecting ActivityLog.xml, shows among a few other error lines:

Still unable to load MEF component DLL: Could not load file or assembly 'CSharpExtensions.Annotations, Version=2.5.65.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. C:\USERS\NOAH\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\16.0_DD51F7B3\EXTENSIONS\CI1WBX4I.BGC\MappingGenerator.dll

Is there something I can do to resolve this, or provide more info? I'm running VS 2019 Community 16.7.2 with MappingGenerator 1.17.435.

cezarypiatek commented 3 years ago

Hi @NoahStahl Thanks for reporting this issue. I've just released a fixed version 1.17.437 Could you update to the newest version and let me know if the issue is gone?

NoahStahl commented 3 years ago

Thanks for the quick reply! I installed the update and now see a different error, below.

I can reproduce with the following. Error occurs as soon as StartsWith() is entered.

string test = "test";
test.StartsWith()

System.ArgumentException: Syntax node is not within syntax tree at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(ExpressionSyntax expression, CancellationToken cancellationToken)at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoFromNode(SyntaxNode node, CancellationToken cancellationToken)at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoCore(SyntaxNode node, CancellationToken cancellationToken)at MappingGenerator.RoslynHelpers.SemanticModelExtensions.GetTypeForSymbol(SemanticModel semanticModel, ISymbol symbol)at MappingGenerator.Mappings.SourceFinders.LocalScopeMappingSourceFinder.<>cDisplayClass9_0.b1(ISymbol x)at System.Linq.Enumerable.WhereListIterator1.MoveNext()at System.Collections.Generic.List1..ctor(IEnumerable1 collection)at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)at MappingGenerator.Mappings.SourceFinders.LocalScopeMappingSourceFinder.FindMappingSource(String targetName, AnnotatedType targetType, MappingContext mappingContext)at MappingGenerator.MethodHelpers.MethodHelper.FindArgumentsMatch(ImmutableArray`1 parameters, IMappingSourceFinder mappingSourceFinder, MappingContext mappingContext)at MappingGenerator.MethodHelpers.MethodHelper.<>cDisplayClass0_0.b0(ImmutableArray1 x)at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()at System.Linq.Buffer1..ctor(IEnumerable1 source)at System.Linq.OrderedEnumerable1.d1.MoveNext()at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)at MappingGenerator.MethodHelpers.MethodHelper.FindBestParametersMatch(IMappingSourceFinder mappingSourceFinder, IEnumerable1 overloadParameterSets, MappingContext mappingContext)at MappingGenerator.Features.Suggestions.MethodParametersSuggestionProvider.GetArgumentListWithLocalVariables(Document document, IInvocation invocation, Boolean generateNamedParameters, SemanticModel semanticModel)at MappingGenerator.Features.Suggestions.MethodParametersSuggestionProvider.SuggestMethodParameters(CompletionContext context, IInvocation invocation, SemanticModel semanticModel)at MappingGenerator.Features.Suggestions.MethodParametersSuggestionProvider.d3.MoveNext() --- 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 Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.d35.MoveNext() --- 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 Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.d29.MoveNext() --- 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 Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.d26.MoveNext() --- 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 Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion.CompletionSource.d25.MoveNext() --- 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 Microsoft.VisualStudio.Text.Utilities.GuardedOperations.d__36`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

cezarypiatek commented 3 years ago

What do you mean by " as soon as StartsWith() is entered"? Looking good on VS 16.5.4, I'm trying to update my VS to the newest version.

UPDATE: I'm not able to reproduce it with VS 16.7.2. Can you attach a sample solution where this problem is reproducible?

NoahStahl commented 3 years ago

Here's a video. Notice the yellow exception notification pop up right when the method parentheses are typed:

https://www.screencast.com/t/6qtmSc4yaH

cezarypiatek commented 3 years ago

It looks like the MethodParametersSuggestionProvider is broken or there is an issue with the part of VS responsible for loading suggestion providers. I need to debug it. I will let you know when I find something.

cezarypiatek commented 3 years ago

I not able to reproduce this issue but I suspect it's caused by the local symbols from outside the codebase. Here's a pre-release version with an attempt to fix that issue. Can you install it and check if this works correctly? https://ci.appveyor.com/api/buildjobs/ht21ewfbkabqddcl/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix

NoahStahl commented 3 years ago

I was able to narrow the issue down to files that have a using static statement. Here's a simple repro solution with a single static class referenced from vanilla Program.cs:

https://github.com/NoahStahl/MappingGeneratorRepro1

(I'd prefer not to install pre-release direct download versions if possible). Hope this helps to narrow it down.

cezarypiatek commented 3 years ago

Thanks for the repro-solution. I will check it today later.

cezarypiatek commented 3 years ago

@NoahStahl I wasn't able to reproduce this issue in a deterministic way but I removed a suspicious code that might cause the problem. An officially release version 1.17.442 should contain a fix

NoahStahl commented 3 years ago

I can confirm no longer occurs in either my project or the repro solution. Nice work!