-
“QTAgent32.exe reagiert nicht mehr” appears when running unit-tests
Situation You are writing unit-tests and maybe are refactoring the implementation along the way. Problem “All of a sudden” QTAgent32.exe crashes when you run the tests. Solution A unit-test (or changed implementation) most probably caused a stack overflow. Attach the debugger to QTAgent32.exe (use the “Debug” button on the crash-window), so you can see the…
-
Get PublicKeyToken of an assembly reference from within Visual Studio
Situation You need the public key token of an assembly reference. E.g. to set the InternalsVisibleTo() attribute for a Unit-Test. Problem There is no standard mechanism embedded in Visual Studio (2010). Solution Create a “external tool” entry that calls sn.exe and redirects the output to the output window. Dialog: [Tools] – [External tools…] – [Add]…
-
XmlSerializer throws FileNotFoundException when debugging
Situation You are using a XmlSerializer. Problem The constructor XmlSerializer(Type) throws a FileNotFoundException when debugging. Solution Pre-Compile the Serializer. See http://msdn.microsoft.com/en-us/library/ee704594.aspx for details. Alternative Configure Visual Studio not to break on System.IO.FileNotFoundException thrown by the CLR through opening the dialog [Debug] – [Exceptions] and unchecking the checkbox for “Common Language Runtime Exceptions” – “System.IO” – “System.IO.FileNotFoundException” Sources…
-
The invocation of the constructor on type X that matches the specified binding constraints threw an exception
Situation You want to edit a WPF application using Visual Studio. Problem Visual Studio throws a XamlParseException that says ‘The invocation of the constructor on type X that matches the specified binding constraints threw an exception’. Solution Open the dialog [Debug] – [Exceptions] (CTRL+D, E) and check the ‘Thrown’ checkbox for ‘Common Language Runtime Exceptions’.…
-
FxCop ignores GlobalSuppressions
Problem FxCop ignores the GlobalSuppressions file. Solution Open the build properties of the project ([Menu] – [Project] – [Properties] – [Build]) Add “CODE_ANALYSIS” to field [Conditional compilation symbols]. Hint: This field may be different between Debug and Release mode.
-
Using reflection to unit-test private methods
Situation There is a class called “MyClass” which has a private method called “MyPrivateMethod” (which expects a single string parameter) that you want to unit-test. Problem You can’t access private methods from the test class by just calling them. Solution Use reflection to invoke the method. typeof(MyClass).GetMethod(“MyPrivateMethod”, BindingFlags.NonPublic | BindingFlags.Instance) .Invoke(null, new object[] { “MyStringParameter” }); Hint: Static methods require the BindingFlag…