Build/Test Issues

"Friend access was granted to" error with internals visible to

Started by theperm on 12,372 views

I have a project that ncrunch fails to build that has a number of projects thats its internals are visible too. It gives this error message

Some.dll (0): Friend access was granted to 'My.FriendProject, PublicKey=xyz', but the output assembly is named 'My.FriendProject, Version=1.1.0.999, Culture=neutral, PublicKeyToken=null'. Try adding a reference to 'My.FriendProject, PublicKey=xyz' or changing the output assembly name to match.

I dont understand this message and how to fix it. Added a reference to MyFriendProject would be a circualr dependancie and Some.dll already has a reference to My.FriendProject
Hi, thanks for sharing this issue.

Is it possible that you have the prevent signing of assembly configuration setting enabled on the project that declares the InternalsVisibleToAttribute?

If so, NCrunch will likely build the 'friend' assembly using a different strong name to that which is declared in the InternalsVisibleToAttribute. This will invalidate the attribute and produce the error you've described.

There can also be other things inside your build process that cause this problem, depending upon how heavily the build process has been customised and whether or not you're using any packages or products that manipulate the build process. This can also be caused by differences between NCrunch's build and Visual Studio's build because of the way VS injects certain properties.

The solution to the problem is generally to adjust the InternalsVisibleToAttribute declaration so that it includes the strong name of the assembly as built by NCrunch. To prevent this from breaking your existing code built outside of NCrunch, you can specify it using a compiler condition. For example:

#if NCRUNCH
[assembly: InternalsVisibleTo("My.FriendProject, Version=1.1.0.999, Culture=neutral, PublicKeyToken=null")]
#else
[assembly: InternalsVisibleTo("My.FriendProject, PublicKey=xyz")]
#endif

Post a reply

Log in to reply.