Skip to main content

Posts

Showing posts from December, 2017

WSFederation OWIN - Could not load type 'System.IdentityModel.Tokens.TokenValidationParameters' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.0.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

At one of my clients we are (still) using ASP.NET MVC 5 and Web API 2. To secure these web applications we use the WSFederation OWIN middleware together with ADFS. This combination works nice and helps us keeping our applications secure. Today one of the teams contacted me and complained that the middleware no longer worked. The error message they got looked like this: Could not load type 'System.IdentityModel.Tokens.TokenValidationParameters' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.0.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The root cause of the problem could be found in the version number, they accidently upgraded the System.IdentityModel.Tokens.Jwt assembly from version 4 to 5. It turns out that version 5 is no longer compatible with OWIN. After reverting back to version 4, everything returned back to normal…

TFS 2017 Build- MSTest v2 tests are not recognized

After upgrading our unit tests to MSTest v2 we noticed that our tests were no longer discovered by the VSTest task on our build agent. As a solution, we decided to invoke the test execution ourself. Therefore I added 2 tasks to our Build definition: One command line task to execute dotnet test One task to collect and publish the test results In the command line task I configured the following settings: To execute the dotnet command we specify ‘dotnet’ as the Tool We also specify the following arguments: test: we want to execute the test commando --no-restore: the package restore already happened in a previous build step and shouldn’t be re-executed here --no-build: assembly compilation already happened in a previous build step and shouldn’t be re-executed here --logger:trx: output the test results in the trx format A last important setting that we change is the ‘Continue on error’ setting is set to true. If we don’t do t

Designing, building, and operating microservices on Azure

Perfect reading material for during the Christmas holidays! Microsoft released some new material together with a reference implementation on how to build a microservices application on top of the Azure platform. Microservices have become a popular architectural style for building cloud applications that are resilient, highly scalable, and able to evolve quickly. To be more than just a buzzword, however, microservices require a different approach to designing and building applications. In this set of articles, we explore how to build and run a microservices architecture on Azure. Topics include: Using Domain Driven Design (DDD) to design a microservices architecture. Choosing the right Azure technologies for compute, storage, messaging, and other elements of the design. Understanding microservices design patterns. Designing for resiliency, scalability, and performance. Building a CI/CD pipeline.

VS Code–Import Cost extension

The more I use VS Code, the more I love it. It is fast and offers an ever growing list of great extensions. One of the extensions I added recently is the Import Cost Extension . From the documentation : This extension will display inline in the editor the size of the imported package. The extension utilizes webpack with babili-webpack-plugin in order to detect the imported size.   On one of the Angular projects I’m working I saw our (minified) vendor.bundle.js file growing to 8MB(!) in size. People were importing any library they found useful without being aware of the extra cost it introduces. With the help of the Import Cost extension, you see the cost early and maybe think twice before you import another library. I’m a fan! More information: https://hackernoon.com/keep-your-bundle-size-under-control-with-import-cost-vscode-extension-5d476b3c5a76

Angular–CompareWith

Angular 4 introduces a new directive that helps you compare select options. This directive is especially useful when your select options are dynamically populated. Let’s explain why… Here is a sample component that contains a dropdown with some options: We set the default option by passing the object reference through the FormControl constructor. Problem is now that when we repopulate our options list(for example through an HTTP call), the object reference is gone and the model binding of our selected value is lost. To solve this problem we can use the compareWith directive which will no longer compare the object references but uses a boolean expression or function instead:

Error CS1525: Invalid expression term 'throw'

On our build server we noticed that one of our builds failed with the following error message: Error CS1525: Invalid expression term 'throw' When building the project locally in Visual Studio, we had no errors ? We found a solution here that worked for us as well: Update Microsoft.Net.Compilers to 2.0.1 or greater. We did an Update-All of the NuGet package at the solution level after which the error disappeared…

Create a .npmrc file on Windows

Kind of stupid but Windows doesn’t like it when you try to create a file with only an extension(like .gitignore, .npmrc,…). Windows will give you an error message instead: The trick to get it working is to include an ending dot also, like .npmrc. Don’t ask me why it works…

Lettable operators in RxJs

After upgrading to Angular 5 (and having some trouble with RxJs but that is for another post), I noticed the introduction of "lettable operators", which can be accessed in rxjs/operators. What is a lettable operator? A lettable operator is basically any function that returns a function with the signature: <T, R>(source: Observable<T>) => Observable<R> . Euhm, what?! Simply put, operators (like filter, map, …) are no longer tied to an Observable directly but can be used with the current let operator(explaining the name). This means you can no longer use the dot-chaining, but will have to use another way to compose your operators. Therefore is a pipe method built into Observable now at Observable.prototype.pipe: Why lettable operators? Lettable operators were introduced to solve the following problems with the dot-chaining(from the documentation ): Any library that imports a patch operator will augment the Observable.prototype for all c

PostgreSQL: Identify your slowest queries

PostgreSQL provides a large list of modules that extends its core functionality. One of these modules is the pg_stat_statements module that provides a means for tracking execution statistics of all SQL statements executed by a server. Before you can use this module, it must be loaded by adding pg_stat_statements to shared_preload_libraries in postgresql.conf , because it requires additional shared memory. This means that a server restart is needed to add the module. After loading the module you can execute the below query to get the top 5 duration queries executed during your performance/benchmarking run: It is recommended to reset the pg_stat_statements using the query below to ensure that you only capture the statements from your performance/benchmarking run:

System.Data.SqlClient.SqlException : The ntext data type cannot be selected as DISTINCT because it is not comparable

After upgrading to NHibernate 5, one of our integration tests started to fail with the following error message: System.Data.SqlClient.SqlException : The ntext data type cannot be selected as DISTINCT because it is not comparable. The error itself happened inside a by Nhibernate generated query: Message: NHibernate.Exceptions.GenericADOException : [ SQL: select distinct supplier1_.SupplierID as supplierid1_138_, supplier1_.Address as address2_138_, supplier1_.City as city3_138_, supplier1_.CompanyName as companyname4_138_, supplier1_.ContactName as contactname5_138_, supplier1_.ContactTitle as contacttitle6_138_, supplier1_.Country as country7_138_, supplier1_.Fax as fax8_138_, supplier1_.HomePage as homepage9_138_, supplier1_.Phone as phone10_138_, supplier1_.PostalCode as postalcode11_138_, supplier1_.Region as region12_138_ from Products product0_ inner join Categories category2_ on product0_.CategoryID=category2_.CategoryID, Suppliers supplier1_ where supplier1_.Supplie

Angular 5 - EmptyError: no elements in sequence

After upgrading to Angular 5, the first run of my application ain’t a big success. I ended up with the following error message when I tried to navigate using the Angular Router: EmptyError: no elements in sequence The problem turned out not to be related to Angular directly but to RxJS 5.5.3. Reverting to 5.5.2 resolved the problem. npm install rxjs@5.5.2 More information: https://github.com/angular/angular/issues/20752

Angular Update Guide

With the fast cadence that new versions of Angular are released, it is not always easy to know what steps are necessary to go from one version to another. To help you, you can use the Angular Update Guide: https://angular-update-guide.firebaseapp.com/ . This is a small application that asks you the following questions: From what version to what version do you want to migrate? How complex is your app? Do you use ngUpgrade? What Package Manager do you use? After answering all these questions, you can click the Show me how to update! button and you get a step by step guide:

NHibernate 5–Async/await

With all the fuzz about .NET Core I almost forgot that NHibernate 5 was released a month ago. One the things I was waiting for was the introduction of async/await to optimize IO bound methods. And after waiting for a loooooong time it’s finally there:

TypeScript: Variable 'require' must be of type 'any', but here has type 'NodeRequire'.

After loading a solution for a code review, I was welcomed by the following error message: Variable 'require' must be of type 'any', but here has type 'NodeRequire'. Google brought me to the following GitHub issue; https://github.com/Microsoft/TypeScript/issues/16298 where the proposed solution was as simple as beautiful: There must be another definition of require somewhere. And indeed, after triggering a search on my solution I found another ‘declare var require’ somewhere in a typedefinition file. After removing it, the error disappeared (and everything still worked).

The request was aborted: could not create SSL/TLS secure channel–Part 3

A colleague asked for help with the following problem: He has an ASP.NET MVC website that talks to an ASP.NET Web API backend. On development everything works as expected but on the acceptance environment, he suddenly start to get TLS errors when the httpclient invokes a call to the backend: The request was aborted: Could not create SSL/TLS secure channel. Let’s take you through the journey that brought us to our final solution. Part 3 – The registry hack Our acceptance and production environments are still Windows Server 2008 R2. On these OS TLS 1.0 is still the default. We can change this by altering the registry: Open the registry on your server by running ‘regedit‘ Browse to the following location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols Add the TLS 1.1 and TLS 1.2 keys under Protocols Right click on Protocols and click New –> Key Create 2 keys Client and Server under both

The request was aborted: could not create SSL/TLS secure channel–Part 2

A colleague asked for help with the following problem: He has an ASP.NET MVC website that talks to an ASP.NET Web API backend. On development everything works as expected but on the acceptance environment, he suddenly start to get TLS errors when the httpclient invokes a call to the backend: The request was aborted: Could not create SSL/TLS secure channel. Let’s take you through the journey that brought us to our final solution. Part 2 – The unexpected .NET Framework update(again). As mentioned in Part 1 , the problem started to appear after a rollout of .NET Framework 4.6. Now what made it even stranger is that we didn’t saw the issue on our production environment. So why didn’t it work on our acceptance environment and did it work on our production environment? Turned out that on our production enviroment another .NET Framework update was executed and that the behavior of the HttpClient changed (again): From the documentation : Default operating system support