5

I have looked into google and stack over flow and read all the posts regarding how to get InternalsVisibleTo to work.

But its not working for me.

Please do not down vote this question because I have tried my best to look and implement the answers on the forums..

My code is as follows:

* Inside TestInternal project *

namespace TestInteral
{
    [TestClass]
    public class MyProviderTest
    {
        [TestMethod]
        public void TestBar()
        {
            bool retval = false;

            retval = new MyProviderClass().Bar();

            Assert.AreEqual(true,retval);
        }

    }
}

* Inside Provider Project *

[assembly: InternalsVisibleTo("TestInternal")]
namespace Provider
{

    public class MyProviderClass
    {
        internal bool Bar()
        {
            return true;

        }

        private void UseBar()
        {
            bool retval = Bar();

        }
    }
}

I am getting the following error in my test class.

Error 1 'Provider.MyProviderClass' does not contain a definition for 'Bar' and no extension method 'Bar' accepting a first argument of type 'Provider.MyProviderClass' could be found (are you missing a using directive or an assembly reference?)

Please let me know how I could use the InternalsVisibleTo correctly so I could correctly test the Internal method in the MyProviderClass.

Thanks

Community
  • 1
  • 1
dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200
  • Are you sure that you have Provider project referenced in TestInternal? Did you try building Provider project first? Is Provider project signed? – cre8or May 14 '12 at 18:13
  • Provider is referenced in TestInternal. I successfully *first* built Provider Project. Provider Project is NOT signed. thanks.. – dotnet-practitioner May 14 '12 at 18:16
  • According to MS documentation both assemblies should be either unsigned or signed – dotnet-practitioner May 14 '12 at 18:20
  • Can you confirm that `TestInteral` is the name of the _assembly_, and not just the namespace? – Douglas May 14 '12 at 18:26
  • Right, plus there's some stuff to do with the keys... "TestInternal" in your InternalsVisibleTo attribute is name of the project? It should be... It's just coincidence that it matches name of the namespace then? – cre8or May 14 '12 at 18:26

1 Answers1

13

Assuming you have just copied and pasted your EXACT code into the question, this is a simple typo. I noticed your namespace on the test assembly is TestInteral with no 'N'. And your InternalsVisibleTo declaration has the last 'N':

[assembly: InternalsVisibleTo("TestInternal")]

That's probably all it is.

Steve Danner
  • 21,818
  • 7
  • 41
  • 51