nsubstitute / NSubstitute.Analyzers

Roslyn analysers for NSubstitute.
MIT License
30 stars 7 forks source link

NS2003 false-positive when InternalsVisibleTo is defined in .csproj #210

Closed rklec closed 1 year ago

rklec commented 1 year ago

STR

Have this in your .csproj

  <ItemGroup>
    <InternalsVisibleTo Include="ProjectName.Test" />
    <InternalsVisibleTo Include="ProjectName.IntegrationTest" />
  </ItemGroup>  

What happens

The issue is you anyway get the error:

NS2003 Can not substitute for internal type. To substitute for internal type expose your type to DynamicProxyGenAssembly2 via [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

grafik

What should happen

No error. After all I can import and use it, this kind-of proves that this works.. Also the tests still execute.

The correction it suggests is also adding InternalsVisibleTo, but I already did that - it just suggests the C# code version.

System

.NET 6

    <PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
rklec commented 1 year ago

Ah, forget it, I should read, you need to expose it to your assembly, too:

    <InternalsVisibleTo Include="DynamicProxyGenAssembly2" /> 

This also removes the linting/analyzer warning. Sorry.