2

Got 2 assemblies Company.BusinessLogic and Company.Tests.

Company.Tests got reference to Company.BusinessLogic.

Need to test internal stuff in BusinessLogic from test project, so added into Business project AssemblyInfo.cs following line:

[assembly: InternalsVisibleTo("Company.Tests")]

But I get build error:

Error 134 Friend assembly reference 'Company.Tests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. C:..\Company.BusinessLogic\AssemblyInfo.cs 61 31 Company.BusinessLogic

I do not want to sign assemblies, because BusinessLogic got a lot of references to other unsigned assemblies.

The MSDN states, that InternalsVisibleTo should work when both assemblies are signed or both are unsigned (under Remarks and Examples sections):

If both assemblies are unsigned, the assemblyName argument consists of the name of the friend assembly, specified without a directory path or file name extension.

Using: .NET: 4.5.2, Visual Studio 2013 Ultimate

How can I fix this error?

mimo
  • 6,221
  • 7
  • 42
  • 50
  • 2
    The implication here is that the unit test project is signed. – Matthew Watson Jun 28 '17 at 14:26
  • Tried to sign just Test project, but getting the same build error . When also append PublicKey to `InternalsVisibleTo("Company.Tests")]`, then it starts to complain, that BusinessLogic logis is not signed. – mimo Jun 28 '17 at 14:35
  • _"I do not want to sign assemblies"_ -- then don't. The error you are asking about happens _only_ if the assembly is signed. So, since you are getting that error, you must be signing the assembly. Since you say you don't want to do that, just stop doing that and the error will go away. – Peter Duniho Jun 28 '17 at 17:10
  • Have the Test Project configured NOT to "Sign the Assembly" (under project properties > Signing tab). I have tried to clean solution multiple times, restart Visual Studio, checked Tests.csproj xml for sign element. Signing is not configured and I still get the build error. – mimo Jun 28 '17 at 19:10
  • When I run `sn -v Company.Tests.dll` got back `Company.Tests.dll does not represent a strongly named assembly`. So it is not signed. Is it a bug in VS 2013 then? – mimo Jun 28 '17 at 19:16
  • @PeterDuniho You flagged this as duplicate inappropriately. The other questions on S.O. are dealing with Signed Assemblies.@mimo Check your Company.BusinessLogic project and ensure that the `[assembly: AssemblyKeyName("")]` line is commented out in its AssemblyInfo.cs file. – AlwaysLearning Jan 14 '19 at 02:24
  • @AlwaysLearning Thanks! – mimo Jan 21 '19 at 09:03

0 Answers0