This is a migrated thread and some comments may be shown as answers.

TypeAccessException when trying to return an internal property

1 Answer 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Muljadi Budiman
Top achievements
Rank 1
Muljadi Budiman asked on 08 Nov 2012, 08:53 PM
Hi.

I have the following code snippet:
public class Class1
{
    public Class1()
    {
        Parameter = new VMParameter() { Token = 21 };
    }
 
    internal VMParameter Parameter { get; set; }
}
 
internal class VMParameter
{
    public int Token { get; set; }
}
 
// Unit Test
[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var c = Mock.Create<Class1>(Behavior.CallOriginal);
        var p = Mock.Create<VMParameter>();
        p.Token = 1;
        Mock.Arrange(() => c.Parameter).Returns(p);
        Assert.AreEqual(c.Parameter.Token, 1);
    }
}

The error message is:
Test method TestProject1.UnitTest1.TestMethod1 threw exception: 
System.TypeAccessException: Attempt by method 'Class1_Interceptor_c1e1c12fbbc845f8a8921237e642d7ff.Intercept(TryJM.Class1, Boolean ByRef)' to access type 'TryJM.VMParameter' failed.

I've followed the instruction at http://www.telerik.com/help/justmock/basic-usage-mock-internal-types-via-proxy.html to add the InternalsVisibleTo to the Telerik.JustMock assembly.

My guess is that the interceptor class is generated dynamically and the 'assembly' of that dynamically generated type doesn't have the InternalsVisibleTo attribute applied to it.  Any suggestions for a workaround for this?

Ciao.
Muljadi Budiman.

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 13 Nov 2012, 04:17 PM
Hi Muljadi,

 Thank you for reporting this unexpected beahvior to us.

 At this point our development team is working on a solution to this issue. You will be notified as soon as we are ready with the fix.

 Till then, please do not hesitate to contact us if there is anything else you would like to ask.

Regards,
Kaloyan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Muljadi Budiman
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or