问题描述
我在我的C#解决方案3的项目。
I have 3 project in my C# solution.
- 签名
- 结构
- 测试
签名具有公共和内部接口。
,它同样具有
Signatures has public and internal interfaces. Also it has
[assembly: InternalsVisibleTo("Structures")]
[assembly: InternalsVisibleTo("Tests")]
在AssemblyInfo.cs中。
in AssemblyInfo.cs of.
结构具有公共和内部类以及
Structures has public and internal classes and
[assembly: InternalsVisibleTo("Tests")]
在AssemblyInfo.cs中。
in AssemblyInfo.cs of.
测试旁边源
<packages>
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="1.2" targetFramework="net45" />
</packages>
在packages.config的NuGet包。
as NuGet packages in packages.config.
我写了从内部签名接口与内部类从结构的一些单元测试。运行,并有下一个结果:异常:
I wrote some unit test for internal interface from Signatures and internal class from Structures. Run, and had next result: exception:
键入Signatures.InterfaceX是不可见的DynamicProxy。无法为不可访问的类型创建代理。令类型的公共或内部和标记与[大会:InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]您的程序集。属性
似乎合乎逻辑。我加
[总成:InternalsVisibleTo(InternalsVisible.DynamicProxyGenAssembly2)],以签名和结构项目的程序集信息。运行,并有下一个结果:异常:
Seems logical. I added [assembly: InternalsVisibleTo("InternalsVisible.DynamicProxyGenAssembly2")] to assembly info of Signatures and Structures projects. Run, and had next result: exception:
键入Castle.Proxies.IReminiscenceableDataTableProxy从程序集DynamicProxyGenAssembly2,版本= 0.0.0.0,文化=中立,公钥=空'正试图实现一个人迹罕至的接口。
这是为了帮助,但没有。
唯一变化异常消息。
This was to help, but didn't. Only change exception message.
如何解决我的问题?
推荐答案
添加这些属性的AssemblyInfo.cs文件
Add both of these attributes to the AssemblyInfo.cs file
[assembly: InternalsVisibleTo("InternalsVisible.DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
然后您的测试项目将能够产生用于接口
Then your test project will be able to generate Moq proxies for the interface
这篇关于怎么办起订量为可见的内部接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!