Excluding Assemblies in ASP.NET Core MVC Controller Discovery

Georg Dangl by Georg Dangl in Web Development Tuesday, July 10, 2018

Tuesday, July 10, 2018

Posted in Asp.Net Core

I'm a big fan of using the Microsoft.AspNetCore.TestHost package to perform integration tests for ASP.NET Core web projects. Even so much that I've put my central OpenId server using IdentityServer4 in a NuGet package, hosting itself in-memory. This let's me perform my integration tests as close to the staging and production environments as possible.

In one project, however, I've had some undesired behavior: Both the OpenId server and the actual project under test defined a route GET /status, so when I tried to request that I got an exception stating that multiple routes matched. That was weird, since there's two TestHost instances in memory. It turns out that with the latest updates, ASP.NET Core scans all loaded assemblies for controllers, so my application under test did also include the controllers from my integration test authentication service.

It's quite an easy fix, though:

Simply make sure that when you're configuring MVC, explicitly exclude assemblies for controller discovery that you want to ignore.

Happy Testing!

 


Share this post


comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.

Dangl.Blog();
// Just 💗 Coding

Social Links