System.Diagnostics.FileVersionInfo is not mockable?

0 votes
>Initialization method *********************************************
threw exception. TypeMock.TypeMockException: TypeMock.TypeMockException: 
*** No method calls found in recording block. Please check:
 * Are you trying to fake a field instead of a property? try to set field
 * Are you are trying to fake an unsupported mscorlib type? See supported types here:</Message>Isolate.WhenCalled(() => FileVersionInfo.GetVersionInfo("")).WillReturn(fakeFileVersionInfo);
the code is
var fakeFileVersionInfo = Isolate.Fake.Instance<FileVersionInfo>(); 
Isolate.WhenCalled(() => fakeFileVersionInfo.ProductName).WillReturn("2015.3.0"); 
Isolate.WhenCalled(() => FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)).WillReturn(fakeFileVersionInfo);

I used TMock from command line through mstest

If FileVersionInfo is not mockable, is there any workaround?

asked Jan 5 by daily2432121 (150 points)

1 Answer

0 votes
Best answer


The workaround is to create your own methods, which extracts data from FileVersionInfo.

For example:

string GetProductName(FileVersionInfo info)


return info.ProductName;


And this method you can mock: Isolate.WhenCalled(() =>


answered Jan 25 by eva (1,580 points)
selected Aug 15 by daily2432121