Skip to main content

Posts

Showing posts from January, 2019

ASP.NET Core Diagnostic Scenarios

While browsing through some GitHub repositories I stumbled over this repo by David Fowler(probably this name rings a bell?): Start by having a look at the Guidance markdown file. It provides an entrance to guidance and examples based real customer experiences for: General ASP.NET Core Asynchronous Programming .NET API Gotchas A must read for every ASP.NET (Core) developer!

Config transformations for your app.config

Config transformations are not limited to web.config files. Thanks to tools like SlowCheetah , you can apply this to any config file. If you don’t want to introduce an extra dependency, you can still apply these transformations by using the TransformXml task from the Microsoft.Web.Publishing.Tasks.dll inside your msbuild file: Import the task dll: <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns=" http://schemas.microsoft.com/developer/msbuild/2003 "> <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" /> Call the imported task: <Target Name="AfterBuild"> <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" /> <TransformXml Source="App.config" Transform="App.$(Configuration).config" Desti...

GraphQL–DotNet - Organizing your queries

In GraphQL there is only a single root Query object. As a consequence the root object keeps growing over time. To solve this problem you can split a root object in multiple groups: The trick is to return an empty object. Field<NonNullGraphType<ProductsQuery>>().Name("Products").Resolve( context => new { } ); Remark: This also works for mutations and subscriptions.

Unable to load DLL 'libSkiaSharp' or one of its dependencies: Access is denied.

One of my projects we are using SkiaSharp to create and manipulate images on the server. However when we tried to load the SkiaSharp library through our ASP.NET Core application, we got the following error message: System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: Access is denied. Problem is that this is a native library and the application pool user by default doesn’t have ‘Execute’ permissions to load and run this library. Here are the steps to fix this issue: Go to your local nuget cache , by default %userprofile%\.nuget\packages Search for the SkiaSharp folder Right click on the folder and choose Properties from the context menu The Properties window is loaded. Go to the Security tab and select the application pool identity from the list of users Click on Edit and check the Read and Execute permission in the Allow column Click on OK to apply the changes. That’s it!

Improve your Postman skills using the in-app Postman lessons

Did you know that Postman had in interactive in-app learning center? You can opt-in to any lesson to improve or practice your Postman skills. From the announcement : When you enter the learning center in the app, you’ll see a library of interactive lessons that range from beginner to expert level. We designed the learning center to track your progress, so your lessons will always be geared to your skillset. In addition, we are consistently adding new lessons. Your learning center will automatically populate with new and relevant material for you to master.  Here are some things you can learn right now on Postman’s in-app learning center Designing and mocking APIs (2 lessons) – Designing and mocking your APIs before you build them helps you define dependencies, create contracts, and identify expected functionality as well as potential problems. Debugging and manual testing (4 lessons) – Manually testing and debugging your APIs is a great skill, and it’s t...

Angular Console - The hidden Electron magic

I blogged before about the Angular Console. I don’t use it every day but it has become my ‘go to’ tool when I have to install and try new Angular schematics. The application itself is built as a small Electron app where they are using Electron as a small wrapper around a web app served by chromium and node.js. Don’t believe me? Open your Angular Console app and browse to http://localhost:7777 . Magic happens!

Git- Delete old branches

My list with local branches was going through the roof so it was time to do some cleanup work. Let’s start by looking at all our local branches: $ git branch All our integrations happen on the “development” branch, so let’s have a look at all branches that are already merged to “development”: $ git checkout development $ git branch --merged Now, we can go through the list and remove all outdated branches one by one using: $ git branch –d branch-to-remove Of course as a developer we’ll prefer to automate this. Here is the Powershell script I used: git branch --merged | ?{-not ($_ -like "*development")} | %{git branch -d $_.trim()}

ElasticSearch - The refresh parameter

ElasticSearch is designed as an eventual consistent system, meaning that there is a time gap between the moment a document is indexed and when it becomes available in your search results. This is because ElasticSearch puts documents first in an in-memory buffer. At specified time intervals(by default every second), a refresh operation is triggered that copies the in-memory buffer content to a newly created segment, making the data available for search. You can start playing around with the refresh interval or trigger the refresh operation manually but in general this is not a good idea. A better alternative is to use the refresh parameter when inserting/updating your document. This parameter brings you into control when changes made by a request become visible for search. You have 3 possible options: false: this is the default value, changes to a document are only visible after the next refresh operation true: this forces a refresh in the affected shards wait_for: ...

GraphQL–Apollo Client Devtools

To simplify your GraphQL development workflow, a great extension to your toolbox is the Apollo Client Devtools Chrome extension. This Chrome extension offers the following features: GraphiQL UI: Serves a GraphiQL UI to query your GraphQL endpoint(and local cache) through the Apollo network interface. Queries inspector: View the queries being actively watched on any given page. See when they’re loading, what variables they’re using. Mutations inspector: View executed mutations and variables. Cache: View the state of your client-side cache as a tree and inspect every object inside. Visualize the mental model of the Apollo cache. Search for specific keys and values in the store and see the path to those keys highlighted.

Azure DevOps–Build task - NuGet pack issues

Today I had to configure a new build pipeline. One of the steps in this pipeline is the creation of our NuGet packages that our pushed to our internal NuGet store. Before I always used the (depecrated) NuGet Packager task As I was in an adventurous mood I decided to switch to the latest version. But no luck for me, my first build failed with the following error message: 2019-01-22T14:48:56.7624685Z ##[section]Starting: NuGet pack 2019-01-22T14:48:56.7644225Z ============================================================================== 2019-01-22T14:48:56.7644225Z Task         : NuGet 2019-01-22T14:48:56.7644225Z Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task. 2019-01-22T14:48:56.7644225Z Version...

How to GraphQL? The Fullstack tutorial for GraphQL

In my journey to learn the ins and outs of GraphQL, I found the following great tutorial , starting with a short video introduction followed by a set of tutorials using specific technology stacks.

Angular–Karma - google is not defined

When trying to get our unit tests running using Karma, I got the following error message: “google is not defined” Inside our application we are calling the google map API. During the tests the google map library cannot be found resulting in the error message above. To fix it, we have to add this library to the files section in our karma.conf.js file:

GraphQL Weekly

If you are into GraphQL, I can definitely recommend subscribing to GraphQL Weekly , a weekly newsletter of the best news, articles and projects about GraphQL.

ASP.NET Core IIS - Application failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%'

After deploying an ASP.NET Core application to IIS, it failed to start with the following error message: Application 'MACHINE/WEBROOT/APPHOST/SampleApp/' with physical root 'C:\Sites\sampleapp\' failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', ErrorCode = '0x80070002' : 0. So what is going on? By default when you add a web.config file to your ASP.NET core project, the following configuration is added: You see the 2 environment variables'(%LAUNCHER_PATH%, %LAUNCHER_ARGS%) that are added to the config and also mentioned in the error message above. These 2 variables are their for Visual Studio and are replaced by Visual Studio when you try build and run your app. For example when you do a debug build, the web.config is transformed to: <aspNetCore processPath=" C:\Program Files\dotnet\dotnet.exe " arguments=" exec &quot;C:\projects\sampleapp\bin\Release\netcoreapp2.2\sampleapp.dll&q...

Entity Framework - The DbContext of type 'SampleContext' cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions.

I was looking at some ways to improve the performance of one of our applications. One of the things I wanted to try was to active DbContext pooling( https://bartwullems.blogspot.com/2018/03/entity-framework-core-20dbcontext.html ). Unfortunately after adding the following lines: the application started to fail with this exception message: System.InvalidOperationException: The DbContext of type 'TargetSUContext' cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions.    at Microsoft.EntityFrameworkCore.Internal.DbContextPool`1..ctor(DbContextOptions options)    at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__5`2.<AddDbContextPool>b__5_1(IServiceProvider sp)    at lambda_method(Closure , IBuildSession , IContext ) Let’s take a look at my DbContext and indeed I had multiple constructors: I don’t und...

GraphQL–DotNet–Nullability

In GraphQL all types are nullable by default. In the first version of GraphQL non-null fields were even not supported at all(!). There is a good reason for this; evolvability of your API. Non-nullable fields make it hard to change your contract. Switching from a non-nullable to a nullable field will always be a breaking change. This explains why GraphQL makes every type nullable by default, and you have to explicitly mark a field as non-null by adding the bang character ( ! ) to your schema definition. When you are using GraphQL.NET, the principles above still apply but the library follows some different rules to mark a field as nullable or not. For structs (integers, booleans, …) GraphQL.NET will mark them as not-null by default. You even have to explicitly mark them as nullable(see this post: https://bartwullems.blogspot.com/2018/11/graphqldotnetnullable-types-nullable.html ). For all other types the rules above are followed and every type is nullable by default. If you don’t w...

SQL Server Management Studio–Reports menu is disabled

When opening SQL Server Management Studio, I noticed that the Reports menu item was disabled: I first thought it had to do something with my rights but I was serveradmin on this specific instance. The problem wasn’t related to security but to the fact that I was using an older SQL Server Management Studio version (2012) to a newer SQL Server Database (2016). After installing SQL Server Management Studio 2016 (or later), the menu item was enabled. Problem solved!

NPM–Install a package as a dev dependency

A quick reminder for myself on how to add a NPM package to your devDependencies. npm install --save-dev <packagename> devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. An example:

ASP.NET Core - OIDC middleware - IDX10500: Signature validation failed

Last Friday I had some fun investigating the following problem: We have a frontend Angular application(FrontEnd) with a corresponding backend API(Backend1). This backend API calls another backend(Backend2). All communication is secured through a combination of  OIDC, oAuth and IdentityServer. So what’s the problem; when the backend1 API calls the backend2 API the security handshake fails with the following error message: "Bearer" was not authenticated. Failure message: "IDX10500: Signature validation failed. No security keys were provided to validate the signature." Here are the steps I took to find and fix the issue: Backend2 API I started by taking a look at the Backend2 API logs but this brought no new information: 2019-01-04 08:40:35.377 +01:00 [Information] Starting up 2019-01-04 08:40:36.416 +01:00 [Information] "Bearer" was not authenticated. Failure message: "IDX10500: Signature validation failed. No security keys wer...

Visual Studio 2017 - No projects supported by NuGet in the solution

I started my day with a rather fun error message in Visual Studio. Visual Studio failed in building my application. When I took a look at the error messages I noticed that Visual Studio failed to download all dependencies from NuGet. However when I tried to open the Nuget Package Manager console, I got the following error message: A magical restart did the trick…

Team Foundation Server Version Control–Remove a lock

I thought that the first week of the new year would be a good time do some cleaning and decided to remove some old branches from Team Foundation Server Version Control. However deleting one of the branches failed with the following error message: Another user had one of the files locked inside his (private) workspace which prevented me from deleting this branch. As I couldn’t contact this person, I had to find another solution. Remove the lock Removing a lock can be done using the tf undo command: Open a Visual Studio command prompt Enter the following command tf undo /workspace:FRIEND-PC;personname  /collection:http://servername/DefaultCollection $/xxxx/ProjectFolder/ProjectName/filepath/filename.css Here is an example: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>tf undo /workspace:"Framework en Tooling 169;Bart Wullems" /collection:http://tfs.server.be:8080/tfs/defaultcollection "$/Framework en Tooling/Ma...

IIS–Keep your application running

A few years ago I blogged about a way to keep your web application running in IIS. To summarize the blog posts, IIS 7.5 introduced the Application Initialization Module that allowed you to start a worker process without waiting for a request. To activate this feature you have to dive into the applicationhost.config file directly and change the startMode of your application pool to alwaysRunning : <system.applicationHost> <applicationPools> <add name="DefaultAppPool" autoStart="true" startMode=" alwaysRunning " /> </applicationPools> </system.applicationHost> This will guarantee that the moment your application pool is started, a worker process spins ups decreasing the time to handle the first request. Unfortunately the blog posts wasn’t complete. Although the steps above guarantee that a worker process is spinned up immediately, it doesn’t mean that the application is loaded into the worker process. ...