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
In the "Solution explorer" click on your project assembly name, and then head to "Tools > Get PublicKey".
From the documentation, the assembly-level InternalsVisibleTo attribute: Specifies that all nonpublic types in an assembly are visible to another assembly. This attribute was introduced in C# 2.0, and allows you to specify other assemblies that can see all types and members marked “internal”.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With