.NET Framework以及.NET(Core) 5之前的版本
在AssemblyInfo.cs文件里添加 InternalsVisibleTo 声明
// This assembly is the default dynamic assembly generated by Castle DynamicProxy,
// used by Moq. If your assembly is strong-named, paste the following in a single line:
[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
// Or, if your own assembly is not strong-named, omit the public key:
[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2")]
参考:https://github.com/devlooped/moq/wiki/Quickstart
.NET 5以后的版本
.NET 5以后默认不再生成AssemblyInfo.cs文件,因此需要在项目的csproj文件里添加InternalsVisibleTo配置
<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />
</ItemGroup>
参考:https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#internalsvisibleto
标签:named,assembly,Moq,internal,cs,InternalsVisibleTo,NET From: https://www.cnblogs.com/netry/p/17931100.html