Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rklec opened this issue Aug 24, 2023 · 1 comment
Closed

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

rklec opened this issue Aug 24, 2023 · 1 comment

Comments

@rklec
Copy link

rklec commented Aug 24, 2023

STR

  • Have an internal interface in your project.
  • Have another test project, where you substitute it.

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
Copy link
Author

rklec commented Aug 24, 2023

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.

@rklec rklec closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant