Microsoft .NET offers a very flexible logging system exposed via the System.Diagnostics namespace. Unfortunately (and not surprisingly), by default the pre-packaged listeners do not support writing messages to log4net directly. However, we can extend the logging outputs by implementing custom TraceListeners and when asking our favourite search engine for “TraceListener log4net” we find there are already plenty of implementations of […]
One of the cool features of PowerShell script based Cmdlets is the possibility to define default values for Cmdlet parameters. This is typically done like this: Whenever we invoke such a Cmdlet without specifying the Name parameter the PowerShell runtime will insert the value my default value into that parameter. C# based PSCmdlet provide a similar approach to this by […]
For years all our PowerShell modules we released were script modules (i.e. they were written in PowerShell). However, it is certainly possible to write PowerShell modules in C# as binary modules. Of course there are already plenty discussions whether one or the other approach is better. It really depends on the exact requirements. For us the limitations of Pester (especially […]
Today I had some troubles signing a PDF document with my SuisseID (Smart card version). I first tried to sign the PDF document by using Adobe Acrobat Reader DC. Unfortunately […]
Today’s post goes rather quick … Telerik JustMock in its commercial (i.e. non-free) version provides you the option to mock static classes, which comes in really handy when you want […]
This blog post is about log4net which switches log configurations within a process as soon as two components are using their own log4net configuration. As you can read from our numerous blogs we are using PowerShell in combination with C# quite extensively. In addition we are heavily relying on log4net for logging puposes (see our PowerShell module biz.dfch.PS.System.Logging (available at […]
Today I ran into a problem when all of a sudden my code contracts stopped working – as it seemed. In reality I was missing a simple override in the implementation of a class that derived from a base class. But now for a a concrete example. Suppose you have the following scenario: ContractClassForIArbitraryObject this class holds the contract for […]
I recently noticed an — at least for me — unexpected behaviour when working with Code Contracts in interfaces. When you define a contract for an interface (via ContractClassFor) and implement a class from that interface that contract is certainly enforced. However when you define additional requirements on that implementation class these contracts are evaluated BEFORE the interface contracts. Here […]
I recently ran into a problem when trying to use Code Contracts on Auto-Implemented Properties (i.e. Automatic Properties) combined with a C# interface. I started with a normal interface IScriptInvokerImpl where I wanted to define a method for running a PowerShell script and a public property for the PowerShell instance being used: A first implementation So a first implementation of […]
At d-fens we usually use JetBrains TeamCity as a build server. Because one of our customers uses Jenkins as build server I had the chance to set up a build job for one of our C#/.NET projects on Jenkins. The project I mentioned is a C#/.NET Web Application built with Visual Studio 2013. For testing we make use of the […]
This blog post is a bit more lengthly than my usual posts and the idea came from an issue I faced when working in one of our project where we use an OData v3 REST interface that talks to an MS SQL Server (2012 R2) via EntityFramework v6.1.3. In short: we wanted to implement ‘entity framework row level security’ (in […]
Imagine you have several repositories holding more or less the same code base that only differ in some customer specific functionality. At d-fens we had exactly the before described situation. We made some changes (i.e. new features or bugfixes) to one of the repositories and wanted to apply the changes to the second repo. One possibility is to apply all […]
When using Microsoft CodeContracts your Contract.Requires and Contract.Ensures statements will throw a ContractException which you cannot catch (per design). This means that you cannot use the [ExceptedException] attribute to assert them. Furthermore when mocking with Telerik Justock you cannot use Contract.Ensures and Contract.Requires at all in your stubs, as the stub is expected to be a Func in the form […]
If your are not already using CodeContracts I really recommend to start using them now. And if you are already using them, you will have noticed that their exceptions cannot easily be caught. This is due to a design decision from the design team as stated in their Code Contracts User Manual: 7.6 ContractException The ContractException type is not a […]
I couple of years ago (back in 2010) I assembled a small document on how to use OpenSSL to create and convert X.509 certificates so Windows can properly recognise and […]
Recently I ran into a strange error when working on an ODataController. On several occasions (especially on CREATE or UPDATE operations) we do not want to return the actual underlying entity of the controller, but instead would like to return an entity that can be used for synchronisation such as a Job. So instead of doing something like this and […]