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

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, 2017 by daily2432121 (3,130 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, 2017 by eva (1,580 points)
selected Aug 15, 2017 by daily2432121