Hi Philipp,
I've gone through the code samples, and investigated. Here’s what happens:
When TypeMock is enabled (whether used directly or not), while the code is JITted TypeMock injects instrumentation code (This is done only at runtime, the assembly is not recompiled). When the code is run it calls into TypeMock. And for that it needs permissions. Specifically, it needs SecurityPermission.
When you use:
[assembly: FileDialogPermission(SecurityAction.RequestOptional, Unrestricted = true)]
The RequestOptional part tells the system to refuse any other permissions (other than FileDialog, obviously). In order to call into TypeMock, you need to add the following line in the AssemblyInfo file of your code:
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Unrestricted = true)]
With these two lines, you can run your tests. Now if you want to limit the permission for testing only, you can use it under a #define block. Also, keep in mind that that turning off caspol (The code access security policy tool) is also a valid option. It can be triggered once you start the run, but it always turns on again at the end of the process. You can start the process at the beginning of the build, and kill it at the end, for example.
Let me know if you need additional help.
Gil Zilberfeld
Typemock Support Team