dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.99k stars 4.03k forks source link

CodeStyleOption<bool>.FromXElement(XElement.Parse(value)) in AutomationObject throws #12325

Closed bkoelman closed 7 years ago

bkoelman commented 8 years ago

Version Used: VS2015 Update3, master branch at 2316dd86cb30d4000fda0c70cdc830eb2056ad89.

Steps to Reproduce:

  1. Build Roslyn.sln, start CompilerExtension project, close 2nd instance, start VisualStudioSetup project.
  2. In RoslynDev instance, create a new Console Application.
  3. In package manager console, type:
install-package jetbrains.annotations
install-package resharpercodecontractnullability
  1. Type text inside class Program:
static string Test() { throw new NotImplementedException(); }
  1. Build, Rebuild Solution

Expected Behavior: Analyzer reports on Main method (twice), and Test method. These are shown in Output Window, Error List and in the form of squiggles/codefix in the Code Editor.

Actual Behavior: Output Window shows analyzer output for all three, but Error List and Code Editor do not show diagnostics/fixes for the args parameter.

1>------ Rebuild All started: Project: ConsoleApplication3, Configuration: Debug Any CPU ------
1>e:\bart\documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs(16,23,16,27): warning RNUL: Method 'Test' is missing nullability annotation.
1>e:\bart\documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs(11,35,11,39): warning RINUL: Parameter 'args' is missing item nullability annotation.
1>e:\bart\documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs(11,35,11,39): warning RNUL: Parameter 'args' is missing nullability annotation.
1>  ConsoleApplication3 -> e:\bart\documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

image

It seems that the analyzer output is suppressed for args because another diagnostic is reported at that same location.

mavasani commented 8 years ago

Tagging @heejaechang

@bkoelman - any chance the missing diagnostics are compilation diagnostics? If so, they would be reported only when Full solution analysis is turned on. Can you confirm if you have turned on Full solution analysis?

bkoelman commented 8 years ago

Full solution analysis is turned on in Tools > Options.

bkoelman commented 8 years ago

To be more correct: it's turned on in the default hive, but off in the RoslynDev hive. So effectively, it was turned off.

I've turned it on now. Then during rebuild in second instance, I hit an InvalidCastException at https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs#L526:

An exception of type 'System.InvalidCastException' occurred in mscorlib.dll but was not handled in user code

Additional information: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'.
bkoelman commented 8 years ago

What happens: the build succeeds, but the error list remains Empty. The Code Editor does show squiggles, but hovering over them hits the InvalidCastException. Hope that helps :)

mavasani commented 8 years ago

@bkoelman - Just to confirm, are you seeing this behavior only in the RoslynDev instance or even with Dev14 Update3?

bkoelman commented 8 years ago

Only in RoslynDev that is started from Update3. Normal Update3 is good. Op 5 jul. 2016 5:19 p.m. schreef "Manish Vasani" notifications@github.com:

@bkoelman https://github.com/bkoelman - Just to confirm, are you seeing this behavior only in the RoslynDev instance or even with Dev14 Update3?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dotnet/roslyn/issues/12325#issuecomment-230509782, or mute the thread https://github.com/notifications/unsubscribe/AJ2JlBzdwEUto8fQ1zgFM1YQMWyyksWNks5qSnX0gaJpZM4JDi1b .

heejaechang commented 8 years ago

@mavasani @srivatsn is build diagnostic analyzer supposed to work in roslyndev hive? live diagnostic analyzer works but how about build one? due to versioning I think it doesnt work? (I mean when building roslyn, not user diagnostic analyzer project)

srivatsn commented 8 years ago

@bkoelman deployed the CompilerExtension project - doesn't that hijack the csc that gets called with the just-built compilers? If so build analzyers should work too.

mavasani commented 8 years ago

Yes, and he is seeing correct set of warnings in output window, which means analyzers ran fine during build.

heejaechang commented 8 years ago

@bkoelman does this still repro?

bkoelman commented 8 years ago

Just synced to master at c2f0b6982b09586a4a3dcc4ea364c30364647239. Behavior changed somewhat but is still not as expected.

First, I'm hitting an exception during step 2 multiple times, at https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs#L688 where the passed in value contains "True". It makes sense that this fails to parse as a valid XML element. Looking up the call stack, this comes from https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs#L522. Note that I have never touched these style settings.

Continuing from there:

1>CSC : warning CS8032: An instance of analyzer CodeContractNullability.CodeContractItemNullabilityAnalyzer cannot be created from e:\bart\documents\visual studio 2015\Projects\ConsoleApplication2\packages\ResharperCodeContractNullability.1.0.5\analyzers\dotnet\cs\CodeContractNullability.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer CodeContractNullability.CodeContractNullabilityAnalyzer cannot be created from e:\bart\documents\visual studio 2015\Projects\ConsoleApplication2\packages\ResharperCodeContractNullability.1.0.5\analyzers\dotnet\cs\CodeContractNullability.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
heejaechang commented 7 years ago

@bkoelman is this still an issue?

bkoelman commented 7 years ago

Just synced to master at bf0e9d771d963f1f780108916a433893cfcf3dea. Except for the XML exception in AutomationObject, this works correctly now. Thanks for fixing.

heejaechang commented 7 years ago

@dpoeschl is the xml parsing event above on AutomatinoObject a known issue? basically this throws.

CodeStyleOption.FromXElement(XElement.Parse(value))

heejaechang commented 7 years ago

I am giving the bug to IDE team. since analyzer issues are all resolved. only thing left is IDE team issue.

Pilchie commented 7 years ago

@jasonmalinowski has a bug about that already.

heejaechang commented 7 years ago

closing the issue since IDE team already has separate issue that track AutomationObject issue.