chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I checked following forum post which resolves the problem in case of Assembly without Strong Name.
https://www.typemock.com/community/viewtopic.php?t=1346&start=0&postdays=0&postorder=asc&highlight=internal+interface

But I tried with following simple interface and test case. Both of them are in a Strong-Named assembly.

// Sample Interface Under Test
namespace TestLibrary
{
    internal interface ITestInterface
    {
        bool TestProperty { get; }
    }
}
// Example Test Class
namespace TestLibrary.Tests
{
    [TestFixture]
    public class TestClass1
    {
        [Test]
        [Isolated]
        public void TestFakeInteralInterfaceFromStrongNamedAssembly()
        {
            ITestInterface fakeTestInterface = Isolate.Fake.Instance<ITestInterface>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => fakeTestInterface.TestProperty).WillReturn(true);
            Assert.AreEqual(true, fakeTestInterface.TestProperty);
        }
    }
}


I added following lines in AssemblyInfo.cs file. I didn't include complete public key below as it will mess the structure of this post.

[assembly: InternalsVisibleTo("TestLibrary.Tests, PublicKey=2400000...")]
[assembly:InternalsVisibleTo("DynamicMockAssembly,PublicKey=2400000...")]


When I run the test I get following exception.

System.TypeLoadException : Type 'Mock0000ITestInterface' from assembly 'DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0857b23fb3f20d9' is attempting to implement an inaccessible interface.

BTW, I'm using following tools
- Typemock 5.4.4.0
- NUnit 2.5.2.9222
- Visual Studio 2008
asked by omarfaruk (800 points)

6 Answers

0 votes
I posted this bug almost 1 month ago. And no one responded to this bug.
Is it fixed in the new release or you don't think this is not an important bug to fix ?
answered by omarfaruk (800 points)
0 votes
Hi,

I apologize for the late response.

Just to make sure, did you place the InternalsVisibleTo attribute in the production project where TestInterface is declared?
[assembly: InternalsVisibleTo("DynamicMockAssembly,PublicKey=0024000004800000940000000602000000
240000525341310004000001000100ab8e3015b99a732d20ecb2a29fb3f54288a8a614896e7c5091d7b9045368fe6b8
bfcc72dce4f01b71281eb4e380dcb709c83a5042a54c684a4711248c078fefb01bcdb09a6ce252e0304ed08c6e4ddf6
9212e3d0a770d953572e3c474fc08fe3bdbb2fad97b32c6045c08f34466dc8e07bd255d3dbc72408dce6859edb4b04bf")]


Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
0 votes
I added InternalVisibleTo attribute correctly with Public Key. Still it doesn't work.
answered by omarfaruk (800 points)
0 votes
Let's take it offline.

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
0 votes
I added InternalVisibleTo attribute correctly with Public Key. Still it doesn't work.


Strange, I had *exactly* the same problem and the strong key (not my key, but the one published on this page) solved the issue for me.

Regards,
Martin.
answered by MartinH (3.2k points)
0 votes
Martin is right. I used the wrong public key earlier. I should have used public key of DynamicMockAssembly assembly.

Thanks
answered by omarfaruk (800 points)
...