DanielHWe / sonar-fxcop

FxCop plugin for C# or VB.NET projects
13 stars 6 forks source link

CA1405 COM visible type base types should be COM visible triggered for .netStandard Projects #12

Closed PulsarFX closed 6 years ago

PulsarFX commented 6 years ago

I have a csproj which triggers this when running the sonar-fxcop:

CA1405: COM visible type base types should be COM visible
'ConfigSettingContractResolver' is marked ComVisible(true) but has the following ComVisible(false) types in its object hierarchy: 'DefaultContractResolver'

Which is nonsense to me, as there is no COM in .NET Standard. I also did not do anything to make it ComVisible.

I've put up this sample project to repro:

<PropertyGroup>
      <TargetFrameworks>netstandard20;net461</TargetFrameworks>
</PropertyGroup>

with a class like this:

public class ConfigSettingContractResolver : DefaultContractResolver

DefaultContractResolver is from Newtonsoft.Json package.

The finding can be prevented with this:

#if !NETSTANDARD2_0
    [System.Runtime.InteropServices.ComVisible(false)]
#endif
public class ConfigSettingContractResolver : DefaultContractResolver
{ }

Some version info: VS 2017 15.5.7 and the sonar scanner log:

INFO: Sensor FxCop (cs) [fxcop]
INFO: Executing command: ...FxCopCmd.exe /file:...\Binaries\net461\TestComVisible.dll /ruleset:=... \.sonarqube\out\.sonar\test_test_7B57DD30-0834-41BF-8B2A-3A97F60EC320\fxcop-sonarqube.ruleset /out:...\.sonarqube\out\.sonar\test_test_7B57DD30-0834-41BF-8B2A-3A97F60EC320\fxcop-report.xml /outxsl:none /forceoutput /searchgac
INFO: Microsoft (R) FxCop Command-Line Tool, Version 15.0 (15.0.27019.1) X86
INFO: Copyright (C) Microsoft Corporation, All Rights Reserved.
INFO: 
INFO: Loaded dataflowrules.dll...
INFO: Loaded designrules.dll...
INFO: Loaded globalizationrules.dll...
INFO: Loaded interoperabilityrules.dll...
INFO: Loaded maintainabilityrules.dll...
INFO: Loaded mobilityrules.dll...
INFO: Loaded namingrules.dll...
INFO: Loaded performancerules.dll...
INFO: Loaded portabilityrules.dll...
INFO: Loaded reliabilityrules.dll...
INFO: Loaded securityrules.dll...
INFO: Loaded securitytransparencyrules.dll...
INFO: Loaded usagerules.dll...
INFO: Loaded TestComVisible.dll...
INFO: Initializing Introspection engine...
INFO: Analyzing...
INFO: Initializing Phoenix engine...
INFO: Analyzing...
INFO: Analysis Complete.
INFO: Writing 1 messages...
INFO: Writing report to ...\.sonarqube\out\.sonar\test_test_7B57DD30-0834-41BF-8B2A-3A97F60EC320\fxcop-report.xml...
INFO: Done:00:00:03.9807264
INFO: FxCopCmd.exe ended with the exit code: 1024
INFO: Sensor FxCop (cs) [fxcop] (done) | time=4430ms

Is this a issue with the sonar-fxcop or VS/fxcop itself? I don't get this from inside Visual Studio.

DanielHWe commented 6 years ago

Hi, did you try this with the FxCop.exe itself? Does it has the same finding?

PulsarFX commented 6 years ago

Yes, it is located in the fxcop result file which is stated in

Writing report to ...\.sonarqube\out\.sonar\test_test_7B57DD30-0834-41BF-8B2A-3A97F60EC320\fxcop-report.xml...

excerpt:

...
 <Rules>
  <Rule TypeName="ComVisibleTypeBaseTypesShouldBeComVisible" Category="Microsoft.Interoperability" CheckId="CA1405" BreaksBuild="True">
   <Name>COM visible type base types should be COM visible</Name>
   <Description>COM visible types should have an object hierarchy that is uniformly COM visible.</Description>
   <Resolution Name="Default">{0} is marked ComVisible(true) but has the following ComVisible(false) types in its object hierarchy: {1}</Resolution>
   <Owner />
   <Url>http://msdn.microsoft.com/library/ms182202.aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="90">Error</MessageLevel>
   <File Name="interoperabilityrules.dll" Version="15.0.0.0" />
  </Rule>
 </Rules>
...
DanielHWe commented 6 years ago

Ok, than this is not an issue with the plugin because the plugin also uses the fxcop itself for the analyse.

I will Close the issue and recommand you to ask your question in a more General Forum like MSDN.com or stackoverflow.