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 was trying to mock System.Security.Cryptography.MD5, and was getting an odd exception. Below is the repro code:

var md5 = Isolate.Fake.Instance<System>();
Isolate.WhenCalled(() => md5.ComputeHash(new byte[0])).WillReturn(null);


It throws the following exception:

System.NotSupportedException: Cannot dynamically create an instance of System.Void.
at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at af.b(MethodBase A_0)
at af.a(MethodBase A_0, fu A_1)
at a.a(fu A_0)
at a.c(fu A_0)
at gb.a(fu A_0)
at gb.a(Object A_0, MethodBase A_1, Object[] A_2)
at gb.a(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Boolean A_5, Object[] A_6)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Bo
olean isInterceptedType)
   at Mock0000MD5.HashFinal()
   at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer)
   at ConsoleSandbox.Class1.<>c__DisplayClass1.<Test>b__0()


Instead of the much more friendly and informative exception:

*** No method calls found in recording block. Please check:
 * Are you trying to fake a field instead of a property?
 * Are you are trying to fake an unsupported mscorlib type? See supported types here: https://www.typemock.com/mscorlib-types


Because I wasn't getting the descriptive error, it lead me to believe that the type must not be in mscorlib, when in fact it is, sending me on a while goose chase. It would save a great deal of time to receive the correct exception when attempting something that is not allowed.

Using Isolator 6.0.6.0
asked by allon.guralnek (10.6k points)

1 Answer

0 votes
Hi Allon,

This looks like a bug :twisted:
Thanks for reporting it.
answered by ohad (35.4k points)
...