Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
# Steps to reproduce
- Have a Xamarin iOS or Android project that references Roslyn analyzers through Nuget.
- Build Project in Visual Studio for Mac with MSBuild selected or using MSBuild on the Mac directly in Terminal.
# Expected behavior
Roslyn analyzers are run and evaluate code correctly.
# Actual behavior
Errors similar to the following for are generated for each analyzer and the analyzers are not run
CSC : error CS8032: An instance of analyzer CSharpGuidelinesAnalyzer.Rules.Naming.AvoidMisleadingNamesAnalyzer cannot be created from /Users/kevinford/Documents/Projects/VSLiveCICDDemo/Code/BuildTest/packages/CSharpGuidelinesAnalyzer.1.0.1/analyzers/dotnet/cs/CSharpGuidelinesAnalyzer.dll : Exception has been thrown by the target of an invocation.. [/Users/kevinford/Documents/Projects/VSLiveCICDDemo/Code/BuildTest/iOS/BuildTest.iOS.csproj]
Because of this no project with references to Roslyn analyzer DLLs compile in the newest Visual Studio for Mac.
# Supplemental info (logs, images, videos)
This works fine in the version of MSBuild that comes with Mono 5.0.1. Since Visual Studio Mobile Center is still using Mono 5.0.1, such projects still compile correctly there. Here is a link to a repository that Contains projects that use Roslyn analyzers (See the BuildTest.Droid and BuildTest.iOS projects under the Code\BuildTest directory):
# Test environment (full version information)
Mono Framework 184.108.40.206
Visual Studio for Mac 220.127.116.117
## Bookkeeping note
I will prepare a non-engineering team preliminary quick review for this report.
Created attachment 24211 [details]
Test case (minimal)
This appears to be either an upstream bug or intentional change in the Roslyn `csc.exe` compiler. The same behavior also occurs with the latest .NET toolchain on Windows with no involvement of Xamarin or Mono.
One other observation is that I don't see the same "An instance of analyzer" warnings when using the Analyzer assemblies from the "Microsoft.CodeAnalysis.Analyzers" NuGet package, so there's a chance that the CSharpGuidelinesAnalyzer NuGet package specifically might have a bug or an outdated dependency.
Point #2 from the following excerpt (found via a quick web search) might be relevant:
> > What can be the various reasons for a CS8032 error to be thrown
> The primary reasons are:
> 1. You have an older compiler toolset/VS then the version of
> Microsoft.CodeAnalysis package that your analyzer was built against.
> You need to upgrade your compiler toolset/VS if you face this.
> 2. One of your analyzer dependencies is not marked as an analyzer, and
> hence can't be found at runtime.
And here's another similar comment from the issue tracker of a particular analyzer library:
## Bug status
Because the observations so far indicate that this issue specifically affects the CSharpGuidelinesAnalyzer NuGet package, I will tentatively mark this bug as RESOLVED DOWNSTREAM at this time. I suspect the CSharpGuidelinesAnalyzer maintainers will be interested to track down whether this is an issue in their library or an incorrect upstream change in Roslyn.
## Steps followed to test
1. Download the console test case attached to this comment.
2. Open the project in Visual Studio for Mac to restore the NuGet package.
3. msbuild /t:Build ConsoleApp1.sln
OR create your own project:
1. Create a new "Other > .NET > Console Project".
2. Add the CSharpGuidelinesAnalyzer NuGet package (currently version 1.0.1).
3. Control-click the project name in the Solution pad and select "Add > Add Files", and then add a link to "packages/CSharpGuidelinesAnalyzer.1.0.1/analyzers/dotnet/cs/CSharpGuidelinesAnalyzer.dll".
4. Set the "Build action" of the file to "Analyzer".
5. Build the Console project in the "Debug" configuration.
## "Bad?" Results with `csc.exe` version 18.104.22.168928 (ec1cde8b) and `msbuild.exe` version 15.3.409.57025 on Windows
The build produces warnings as described in Comment 0:
CSC : warning CS8032: An instance of analyzer CSharpGuidelinesAnalyzer.Rules.Naming.AvoidMisleadingNamesAnalyzer cannot be created from C:\source\ConsoleApp1\packages\CSharpGuidelinesAnalyzer.1.0.1\analyzers\dotnet\cs\CSharpGuidelinesAnalyzer.dll : Exception has been thrown by the target of an invocation.. [C:\source\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj]
## "Bad?" Results with Mono 22.214.171.124 (d15-3/da80840) or Mono 126.96.36.199 (2017-06/6425f06)
The build produces warnings as described in Comment 0:
/Users/Shared/Projects/ConsoleApp1/ConsoleApp1/CSC: Warning CS8032: An instance of analyzer CSharpGuidelinesAnalyzer.Rules.Naming.AvoidMisleadingNamesAnalyzer cannot be created from /Users/Shared/Projects/ConsoleApp1/packages/CSharpGuidelinesAnalyzer.1.0.1/analyzers/dotnet/cs/CSharpGuidelinesAnalyzer.dll : Exception has been thrown by the target of an invocation..
(The "VSLiveCICDDemoPublic" test case mentioned in Comment 0 has `<TreatWarningsAsErrors>true</TreatWarningsAsErrors>`, so it displays these as errors.)
## "Good?" Results with Mono 188.8.131.52 (2017-02/9667aa6)
The build produces no warnings that mention "An instance of analyzer" (although in this simple test case, I do get some (probably unrelated) warnings about "Assembly-level attribute ... missing or empty").
Thank you. I will let the package author know. The warning you received with Mono 184.108.40.206 was the analyzer working correctly (that's one of the things it checks for). Thank you for resolving so quickly.