Bernhard Hagmann's Blog

    • Links
    • Source Codes
    • Windows Install
  • 2017-05-14

    Best investments for developers

    Optimizing the office setup can have a great impact on a developers performance. Here are some things that I wouldn’t want to miss ever again: Big Monitor or multiple Monitors Not having to worry about screen estate is a must. Developers use lots of information from different sources all the time, so you should have a really big…

    Hardware, Tools
  • 2016-12-21

    See changed files between GIT commits

    Problem You want to see the changed files between two commits in a GIT repository, e.g. to upload only changes to a webserver. Solution git diff –name-only SHA1 SHA2 Sample git diff –name-only 71d9def3c587ca8d26b8140560f6bb3c89ec9593 HEAD Sources http://stackoverflow.com/a/1552353

    Tools
    git
  • 2015-06-29

    Compact and pretty GIT log

    Problem You want to see all your commits of a git repository but the default “git log” output is not very nicely formatted and verbose. Solution Use the following command: git log –author=”Your Name” –pretty=”%C(yellow)%h%Cred%d%Creset %s%C(white), %C(green)%ar%Creset” The output will look like this: Of course you could also remove the –author parameter or add the –graph parameter…

    Tools
    git
  • 2015-05-12

    checkstyle:check doesn’t use custom ruleset

    Problem You use Checkstyle with custom rules in a Maven build. While the check via mvn install is performed with the custom ruleset, a check via mvn checkstyle:check or checkstyle:checkstyle is performed with the standard (Sun + Maven) ruleset. With some tinkering you can get it to check no rules, but not to use the custom ruleset.…

    Java
    Checkstyle, Maven
  • 2014-09-14

    USB device not recognized / Unknown device / Device descriptor request failed

    Problem A micro USB device (e.g. Smartphone) isn’t recognized by the USB host anymore. Yet the device still charges, so the USB port probably isn’t broken. Solution Use a needle and toothbrush to clean the micro USB port. Remember to turn the device off and ideally remove the battery before cleaning. If that didn’t work……

    Hardware
  • 2014-04-04

    Cyborg R.A.T. Auto Profile Load

    Situation Mad Catz Cyborg R.A.T. mouses can be programmed using Smart Technology profile editor. Problem The activated profile resets every time Windows starts. Solution The profile needs to be saved to a specific folder and marked as startup-profile. Locate the “SmartTechnology Profiles” folder. On a default Windows 8 install it can be found under C:\Users\Public\Public…

    Hardware, Windows
    Cyborg, Mad Catz, R.A.T., Saitek, SmartTechnology
  • 2014-03-20

    ntfs-3g can’t mount NTFS partition

    Problem You can’t mount a NTFS partition using ntfs-3g and the error message states, that the partition is in an “unsafe state”. Solution Put the hard drives into a windows machine. In the power options set Sleep – Allow hybrid sleep to “Off”. Now shutdown the PC with the following command to perform a full…

    Linux, Windows
    hybrid sleep, ntfs-3g
  • 2014-03-19

    CentOS Installation fails – “Unable to read package metadata.”

    Problem CentOS installation fails with the message: “Unable to read package metadata. This may be due to missing repodata directory. Please ensure that your install tree has been correctly generated”. Solution 1 Add the corresponding repository server. In case of CentOS 6.5 64bit: http://mirror.centos.org/centos/6.5/os/x86_64/ Solution 2 See the following stackoverflow thread: http://stackoverflow.com/questions/21637068/unable-to-read-package-metadata-this-may-be-due-to-missing-repodata-directory

    Linux
    CentOS, Installation, Linux
  • 2013-04-08

    WampServer can’t start Apache

    Situation and Problem WampServer can’t start Apache and the windows service (wampapache) can’t be started manually. Solution Make sure no other webserver is running. Check [WampServer context menu] > [Apache] > [Service] > [Test Port 80]. If Visual Studio, WebMatrix or anything similar is installed, IIS could be active. To really get rid of IIS…

    Windows
  • 2012-06-21

    Creating a single executable from multiple .NET assemblies

    Problem You have a .NET application that uses multiple assemblies but you want it as a single executable. Solution Use ILMerge to merge the assemblies into one executable. Solution (with WPF support) Embed the required assemblies as embedded resources in your project and extend the assembly resolving to check the embedded resources (see second link…

    .NET, Tools
    dll, exe, ILMerge, stand-alone
  • 2012-01-26

    WPF image/bitmap rendering optimization (WPF Images/Bitmaps are blurry or pixelated)

    Situation You’re building a WPF application. Problem Some image/bitmap is rendered blurry or pixelated. Solution Modify the rendering  options corresponding to your needs. Options to set on any UIElement (these are inherited by all sub-objects): RenderOptions.BitmapScalingMode UseLayoutRounding Options to set on any image: SnapsToDevicePixels A settings that has worked very well for me is UseLayoutRounding=”true”.…

    .NET
    .NET 4.0, Bitmap, Blurry, Image, Pixelated, Rendering, WPF
  • 2012-01-26

    WPF Text Rendering Optimization (Text of WPF application is blurry or pixelated)

    Situation You’re building a WPF application. Problem Some text is rendered blurry or pixelated. Solution Modify the text render options corresponding to your needs. Properties you can set on any UIElement: TextOptions.TextFormattingMode TextOptions.TextRenderingMode TextOptions.TextHintingMode A settings that has worked for me very well is TextOptions.TextFormattingMode=”Display”. These settings are inherited by all sub-elements so it’s okay…

    .NET
    .NET 4.0, WPF
  • 2011-12-22

    Mocking a generic method (that uses TResult) with Microsoft Moles

    Situation There is a generic method that uses TResult which you want to mock using Microsoft Moles. Problem You can’t just assign a delegate like on a non-generic method. Solution Create a delegate that behaves like the mocked method should. Define the concrete expected parameter types. Instantiate a new MolesDelegates.Func with the corresponding type-parameters and…

    .NET
    Generic, Microsoft Moles, Unit-Test
  • 2011-11-08

    Disable anti-aliasing in WPF

    Situation You’re creating some kind of control that needs to be sharply visible. Problem WPF uses anti-aliasing on default so the control is rendered “soft”. Solution Deactivate anti-aliasing for the whole WPF application, the control or the specific part that needs to be sharp by setting the EdgeModeProperty to aliased. Sample /// <summary> /// Interaction…

    .NET
    WPF
  • 2011-10-28

    “InitializeComponent() does not exist in the current context” after copying XAML files

    Situation You copied XAML files in Visual Studio. Problem Visual Studio now can’t compile anymore, reporting that the InitializeComponent() method in the code-behind of your XAML files does not exist in the current context. Solution The build action of your XAML files has probably changed to “Resource”. Change it (back) to “Page”. Sources http://stackoverflow.com/questions/954861/why-can-visual-studio-not-find-my-wpf-initializecomponent-method

    .NET
    WPF, XAML
  • 2011-10-25

    Localizing WPF controls with ResX files

    Situation You want to localize a WPF control. Problem Books on WPF recommend to use Microsofts LocBaml.exe, which is actually just a sample that is, of course, not integrated anywhere. Solution Localize the WPF control using ResX files. create the ResX files set the scope of the ResX files to public add the Properties namespace…

    .NET
    localization, ResX, WPF
  • 2011-10-24

    Using a CLR-namespace of another assembly in XAML

    Situation You want to use a CLR namespace of another assembly in your XAML. Problem A simple xmlns:custom=”clr-namespace:MyOtherAssembly.MyDesiredNamespace” won’t do the trick. Solution Identify the assembly within the namespace string. Example xmlns:custom=”clr-namespace:MyDesiredNamespace;assembly=MyOtherAssembly” Sources http://msdn.microsoft.com/en-us/library/ms747086.aspx

    .NET
    WPF, XAML
  • 2011-10-24

    Setting the culture on WPF bindings

    Situation You work on WPF bindings, for example a binding to a DateTime object. Problem The DateTime object is displayed in en-US culture format. Solution Set the current culture on the root element, which is most probably the outer most Grid element, of your XAML. For example: Set the culture in the corresponding ViewModel constructor…

    .NET
    C#, WPF
  • 2011-09-26

    “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…

    .NET
    Unit-Test, Visual Studio
  • 2011-09-15

    WPF localization

    Sources ResX: http://compositeextensions.codeplex.com/discussions/52910?ProjectName=compositeextensions MarkupExtension: http://www.wpftutorial.net/LocalizeMarkupExtension.html

    .NET
    localization, WPF
  • 2011-09-15

    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]…

    .NET, Tools
    Visual Studio
  • 2011-09-02

    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…

    .NET
    Debug, Visual Studio, XmlSerializer
  • 2011-09-02

    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’.…

    .NET
    Debug, Visual Studio, WPF, XamlParseException
  • 2011-08-30

    Using Microsoft Moles and dynamics (DLR)

    Situation You want to use the ‘dynamic’ type in your unit-test. Problem An InvalidOperationException that says ‘Dynamic operations can only be performed in homogenous AppDomain.’ is thrown. Solution Changed the attribute ‘enabled’ of the node ‘legacyCasPolicy’ to ‘false’ in the following configuration file: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssembliesMicrosoft.Moles.VsHost.x86.exe.config Sources http://weblogs.asp.net/mjarguello/archive/2011/04/26/using-moles-with-dlr.aspx http://www.cameronfletcher.com/post/InvalidOperationException-Dynamic-operations-can-only-be-performed-in-homogenous-AppDomain.aspx http://social.msdn.microsoft.com/Forums/en/pex/thread/0a931fc1-9049-482a-bf2d-5499ccf65b82 http://stackoverflow.com/questions/4230909/odd-exception-in-mvc-3-project

    .NET
    Microsoft Moles, Mocking, Unit-Test
  • 2011-08-11

    MessageBox in a unit-test

    Situation You want to unit-test a method which uses a MessageBox. Problem The MessageBox will pop up and stop the execution of all tests until the user chooses an action (e.g. presses “OK”). Solution One way around this issue is mocking the MessageBox class to just return the expected DialogResult, which can be done using…

    .NET
    Microsoft Moles, Mocking, Unit-Test
  • 2011-08-11

    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.

    .NET
    FxCop, Visual Studio
  • 2011-08-11

    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…

    .NET
    C#, Reflection, TargetInvocationException, Unit-Test, Visual Studio

Designed with WordPress