TypeAccessException when trying to return an internal property

2 posts, 0 answers
  1. Muljadi Budiman
    Muljadi Budiman avatar
    1 posts
    Member since:
    Sep 2009

    Posted 08 Nov 2012 Link to this post


    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
    public class UnitTest1
        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?

    Muljadi Budiman.
  2. Kaloyan
    Kaloyan avatar
    877 posts

    Posted 13 Nov 2012 Link to this post

    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.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top