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
Hi everyone

I have the following code that throws a TypeMockException: Cannot use Return in this sequence, there must be a mocked statement first.

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
File.Exists(null);
recorder.Return(false);
}

The exception occurs on the recorder.Return(false); line. I have tried this with string.IsNullOrEmpty(null); and Directory.Exists(null); and the same result occurs. Am I doing something wrong?

Ide: VS2005
TypeMock version: 3.6.1.0 with fix for FailWhenCalled (See this thread: https://www.typemock.com/community/viewtopic.php?t=402)
NUnit version: .Net 2 2.2.8

Log:
System.IO.File bool Exists(class System.String)
System.Collections.ArrayList instance class System.Collections.IEnumerator GetEnumerator()
System.Collections.ArrayList+ArrayListEnumeratorSimple void .cctor()
System.Collections.ArrayList+ArrayListEnumeratorSimple instance void .ctor(class System.Collections.ArrayList)
System.Collections.ArrayList+ArrayListEnumeratorSimple instance bool MoveNext()
System.Exception instance void .ctor(class System.String)
System.Exception instance void set_HResult(int32)
System.Reflection.TargetInvocationException instance void .ctor(class System.Exception)
System.Environment class System.String GetResourceString(class System.String)
System.Environment class System.String GetResourceStringLocal(class System.String)
System.Environment void InitResourceHelper()
System.Environment+ResourceHelper instance void .ctor()
System.Environment+ResourceHelper instance class System.String GetResourceString(class System.String)
System.Environment+ResourceHelper+GetResourceStringUserData instance void .ctor(class ResourceHelper,class System.String)
System.Environment+ResourceHelper instance void GetResourceStringBackoutCode(class System.Object,bool)
System.Environment+ResourceHelper instance void GetResourceStringCode(class System.Object)
System.Collections.Stack instance void .ctor(int32)
System.Resources.ResourceManager void .cctor()
System.Resources.ResourceReader void .cctor()
System.Collections.Stack instance void Push(class System.Object)
System.Resources.ResourceManager instance void .ctor(class System.String,class System.Reflection.Assembly)
System.Resources.ResourceManager instance void CommonSatelliteAssemblyInit()
System.Resources.ResourceManager instance class System.String GetString(class System.String,class System.Globalization.CultureInfo)
System.Globalization.CultureInfo class System.Globalization.CultureInfo get_CurrentUICulture()
System.Threading.Thread instance class System.Globalization.CultureInfo get_CurrentUICulture()
System.Globalization.CultureInfo class System.Globalization.CultureInfo get_UserDefaultUICulture()
System.Resources.ResourceManager instance class System.Resources.ResourceSet InternalGetResourceSet(class System.Globalization.CultureInfo,bool,bool)
System.Globalization.CultureInfo instance int32 GetHashCode()
System.Globalization.CompareInfo instance int32 GetHashCode()
System.Globalization.CompareInfo instance class System.String get_Name()
System.Resources.ResourceManager instance class System.String GetResourceFileName(class System.Globalization.CultureInfo)
System.Globalization.CultureInfo instance bool Equals(class System.Object)
System.Globalization.CultureInfo bool VerifyCultureName(class System.Globalization.CultureInfo,bool)
System.Resources.ResourceManager class System.Globalization.CultureInfo GetNeutralResourcesLanguage(class System.Reflection.Assembly,value class System.Resources.UltimateResourceFallbackLocation&)
System.Reflection.CustomAttributeData class System.Collections.Generic.IList`1<class System.Reflection.CustomAttributeData> GetCustomAttributes(class System.Reflection.Assembly)
System.Reflection.CustomAttributeData class System.Collections.Generic.IList`1<class System.Reflection.CustomAttributeData> GetCustomAttributes(class System.Reflection.Module,int32)
System.Reflection.CustomAttributeData instance void .ctor(class System.Reflection.Module,value class System.Reflection.CustomAttributeRecord)
System.RuntimeType class System.Reflection.MethodBase GetMethodBase(class System.Reflection.Module,int32)
System.RuntimeType class System.Reflection.MethodBase GetMethodBase(value class System.ModuleHandle,int32)
System.RuntimeType class System.Reflection.MethodBase GetMethodBase(value class System.RuntimeMethodHandle)
System.RuntimeType+RuntimeTypeCache instance class System.Reflection.MethodBase GetConstructor(value class System.RuntimeTypeHandle,value class System.RuntimeMethodHandle)
System.Reflection.CustomAttributeData value class System.Reflection.CustomAttributeType InitCustomAttributeType(class System.Type,class System.Reflection.Module)
System.Reflection.CustomAttributeData value class System.Reflection.CustomAttributeEncoding TypeToCustomAttributeEncoding(class System.Type)
System.Reflection.CustomAttributeType instance void .ctor(value class System.Reflection.CustomAttributeEncoding,value class System.Reflection.CustomAttributeEncoding,value class System.Reflection.CustomAttributeEncoding,class System.String)
System.Reflection.CustomAttributeCtorParameter instance void .ctor(value class System.Reflection.CustomAttributeType)
System.RuntimeType instance class System.Reflection.FieldInfo[] GetFields(value class System.Reflection.BindingFlags)
System.RuntimeType instance class System.Reflection.FieldInfo[] GetFieldCandidates(class System.String,value class System.Reflection.BindingFlags,bool)
System.RuntimeType+RuntimeTypeCache instance class System.Reflection.CerArrayList`1<class System.Reflection.RuntimeFieldInfo> GetFieldList(value class System.Reflection.MemberListType,class System.String)
System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1 instance class System.Collections.Generic.List`1<class System.Reflection.RuntimeFieldInfo> PopulateFields(value class Filter)
System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1 instance void PopulateRtFields(value class Filter,value class System.RuntimeTypeHandle,class System.Collections.Generic.List`1<class System.Reflection.RuntimeFieldInfo>)
System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1 instance void PopulateRtFields(value class Filter,int32**,int32,value class System.RuntimeTypeHandle,class System.Collections.Generic.List`1<class System.Reflection.RuntimeFieldInfo>)
System.RuntimeFieldHandle instance value class System.Utf8String GetUtf8Name()
System.Reflection.RtFieldInfo instance void .ctor(value class System.RuntimeFieldHandle,class System.RuntimeType,class RuntimeTypeCache,value class System.Reflection.BindingFlags)
System.Reflection.RuntimeFieldInfo instance void .ctor(class RuntimeTypeCache,class System.RuntimeType,value class System.Reflection.BindingFlags)
System.Reflection.FieldInfo instance void .ctor()
System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1 instance void PopulateLiteralFields(value class Filter,value class System.RuntimeTypeHandle,class System.Collections.Generic.List`1<class System.Reflection.RuntimeFieldInfo>)
System.Reflection.MetadataImport instance int32 EnumFieldsCount(int32)
System.Reflection.MetadataImport instance void EnumFields(int32,int32*,int32)
System.Reflection.MetadataImport instance value class System.Utf8String GetName(int32)
System.Reflection.MetadataImport instance void GetFieldDefProps(int32,value class System.Reflection.FieldAttributes&)
System.Refl
asked by Jonathan Khor (1.1k points)

1 Answer

0 votes
Hi Jonathan

The message is misleading in this case.
The problem is that the 'File' class is in mscorlib assembly and sadly we can not mock types in mscorlib. :(
We will try fix message though.
answered by ohad (35.4k points)
...