InternalsVisibleTo does not work

只谈情不闲聊 提交于 2019-11-30 02:39:01
Joe

If your assembly is signed with a strong name look at this answer.

Otherwise check that the name of your test assembly really is "MyTests.dll" (it doesn't have to match the project name, though it will by default).

Lets break it down a bit as many of us has experienced this slight mix-up in the past...

Assembly A has your internal class. Assembly B has your unit tests.

You wish to grant the internals of assembly A visibility in assembly B.

You need to put the InternalsVisibleTo assembly attribute inside assembly A and grant access to assembly B.

You still need your test project to reference your main project.

This can be easy to overlook and if you have no existing test code this may appear like the InternalsVisibleTo is not functioning.

In my case I was coding to an Interface. As interfaces can only specify public properties the internal properties were not present on the interface.

Make sure you're not doing the same thing as I was!

I changed:

Assert.IsNotNull((exportFileManager)?.ThumbnailFileExporter);

To:

Assert.IsNotNull((exportFileManager as ExportFileManager)?.ThumbnailFileExporter);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!