Skip to content

Category: Technology

Anything related to technology

C#/.NET 0

ODataQueryOptions do not correctly apply $filter and $orderby Options to IQueryable when using EntityFramework 6 with SQL Server

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

Various Products 0

Apply Commit from one Repository to another

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

PowerShell 0

[NoBrainer] ‘The Should command may only be used inside a Describe block’ when run in an interactive PowerShell session

Here is a small helper method that you can use when creating Pester tests and trying to run them in an interactive PowerShell session. When executing statements that include the Pester Should Cmdlet interactively in a PowerShell session you receive the following error message: With the Should helper method below you can still execute the original Pester statement without having […]

C#/.NET 0

[NoBrainer] C# UnitTesting with CodeContracts and Telerik JustMock

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

Various Products 1

Unit Testing with Code Contracts

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

PowerShell 0

[NoBrainer] Performance Considerations regarding using Guid.ToString vs Guid.Guid in PowerShell

While doing some performance optimisations on one our loader scripts I came across an issue of converting a System.Guid or [[Guid]] in PowerShell to a string representation. In C# I was always (and still am) using ToString() and never saw anything like a Guid property. However, for some reason in PowerShell I tended to use the Guid property (instead of […]

PowerShell 0

Transient Fault Handling with PowerShell

We are using PowerShell to automate various backend systems quite heavily. Sometimes these interfaces (which may be REST APIs, message queues or something completely different) are shortly not available because of intermittent failures or simply because of network issues. In any case, most of the time a script will crash, though quite a bunch of work in this script might […]

PowerShell 0

Assert and Exception Logging made easy in PowerShell

In this post I would like to present you a way of how to easily perform assertions like error checking and result validation with PowerShell based on an idea of the Microsoft Code Contracts library. We at d-fens spend quite some time writing PowerShell scripts that automate and integrate various backend systems where unforeseen events not only happen but are […]

Various Products 0

ODataController throws ‘No NavigationLink factory was found’ when returning a different type in IHttpActionResult

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

PowerShell 3

[HOWTO] Sign PowerShell Script with SuisseID

We at d-fens all have a SuisseID, which can be used for different purposes like authentication and electronical signing purposes. It’s as well possible to sign code with the SuisseID. The advantages of using the SuisseID for code signing are that the SuisseID is a very cheap in comparison to other code signing certificates and that the user gets authenticated […]

PowerShell 0

GitHub Repository creation with PowerShell

In the last few weeks I had to create several GitHub repositories for my daily work. To simplify the process I automated the creation with PowerShell. I created and initialized the repositories manually until I recognized that this is a perfect task to automate. First I studied the documentation of the GitHub API v3, which is very well documented! Fortunately […]

C#/.NET 1

Using CodeContracts with OData Controllers and Web.Api Exception Filters

When writing ODATA controllers for our projects we spend quite some time on writing boilerplate code and input parameter validation. In addition, for our error handling we would like detailed information for internal troubleshooting but not so detailed information sent back to the client (i.e. no stack traces). In order to achieve this without extra work we started looking at […]

LightSwitch 15

Consuming ODATA Services from LightSwitch with Impersonation

In case you are still using LightSwitch and are not entirely relying on its internal features, you might have started using ODATA services as LightSwitch data sources. This comes in especially handy when combined with the Microsoft Managed Extensibility Framework (MEF) which lets you create decoupled components that can be easily plugged into your core application. However, as soon your […]