How to do internal interfaces visible for Moq?
Add the below to the the csproj file in the project where the classes are defined.
<ItemGroup>
<!-- For Moq to mock internal class objects -->
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
The suggested fix message uses a const/static field for the assembly name:
[assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]
You used a string which does not correspond to the assembly name:
[assembly: InternalsVisibleTo("InternalsVisible.DynamicProxyGenAssembly2")]
Change it to:
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
You can see the actual assembly name (which should appear in InternalsVisibleTo
) in your error message:
Type 'Castle.Proxies.IReminiscenceableDataTableProxy' from assembly 'DynamicProxyGenAssembly2 (...)