Note that there are some explanatory texts on larger screens.

plurals
  1. POaccess to the Object property after new Mock<RadNumericTextBox>() leads to NullReferenceException
    text
    copied!<p>I have to write some tests using moq framework (<a href="https://code.google.com/p/moq/" rel="nofollow">https://code.google.com/p/moq/</a>). I want to check if some value can be read correctly from a telerik textbox in some ASP.NET application. Therefore I want to mock the telerik text box and give this mock as a parameter to the SUT's method to check if it is read correctly.</p> <p>Consider:</p> <pre><code>var telerikFake = new Mock&lt;RadNumericTextBox&gt;(); telerikFake.Setup(x =&gt; x.Text).Returns("23,456"); var result = telerikFake.Object; //The exception comes from inside the telerikFake.Object property implementation </code></pre> <p>Accessing the telerikFake.Object property gives a NullReferenceException with this stack trace:</p> <pre><code>at Castle.DynamicProxy.AttributeUtil.&lt;GetNonInheritableAttributes&gt;d__0.MoveNext() at Castle.DynamicProxy.Contributors.ClassProxyInstanceContributor.Generate(ClassEmitter class, ProxyGenerationOptions options) at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope) at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options) at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) at Moq.Proxy.CastleProxyFactory.CreateProxy[T](ICallInterceptor interceptor, Type[] interfaces, Object[] arguments) at Moq.Mock`1.&lt;InitializeInstance&gt;b__0() at Moq.PexProtector.Invoke(Action action) </code></pre> <p>Do you have any hints under what circumstances the moq frameworks Mock.Object method leads to this error?</p> <p>I found a ticket within the MoQ issue list: <a href="http://code.google.com/p/moq/issues/detail?id=326" rel="nofollow">http://code.google.com/p/moq/issues/detail?id=326</a> . Are there any developers enabled to fix this issue soon? The ticket was created in 2011.</p> <p>Regards, Michael</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload