The .NET Stacks #49: 🌟 Is reflection really that bad?
Tags: csharp, dotnet, azure
Published: 2021-05-15 12:53:47

---
title: The .NET Stacks #49: 🌟 Is reflection really that bad?
published: true
date: 2021-05-15 10:30:00 UTC
tags: csharp,dotnet,azure
canonical_url: https://www.daveabrock.com/2021/05/15/dotnet-stacks-49/
---

_NOTE: This is the web version of my weekly newsletter, which was released on May 15, 2021. To get the issues right away, subscribe at [dotnetstacks.com](https://dotnetstacks.com/)._

Happy Monday! I hope you have a good week. Here's what we have this week:

- Is reflection still valuable?
- IdentityServer templates shipping with .NET 6
- Last week in the .NET world

* * *

## Is reflection still valuable?

Last Monday, Marc Gravell asked: [_is the era of reflection-heavy C# libraries at an end_](https://blog.marcgravell.com/2021/05/is-era-of-reflection-heavy-c-libraries.html)? As C# source generators get more popular, developers might be wondering if it might someday replace the idea of reflection (for the unfamiliar, reflection is a way of discovering types at runtime).

Today, unless we're library authors, a lot of reflection is provided to us without us having to care:

> This provides a pretty reasonable experience for the consumer; their code _just works_, and - sure, the library does a lot of work behind the scenes, but the library authors usually invest a decent amount of time into trying to minimize that so you aren’t paying the reflection costs every time.

As the industry has evolved, we've seen how reflection impacts modern applications. For example, we see increased demands on parallel code (async/await), AOT platforms, runtime error discovery, and more. If you're thinking of the cloud, runtime performance matters (especially if you're paying for serverless and execution times).

Marc states:

> Imagine you could take your reflection-based analysis code, and inject it _way_ earlier - in the build pipe, so when your _library consumer_ is building _their_ code ...  you get given the compiler’s view of the code ... and _at that point_ you had the chance to _add your own code_ ... and have our additional code included in the build ... This solves _most_ of the problems we’ve discussed.

This doesn't mean reflection doesn't have its use cases, and it's so pervasive in the .NET ecosystem it [isn't going anywhere anytime soon](https://twitter.com/davidfowl/status/1389317488882552832). Source generators are great for resolving performance headaches with certain reflection use cases like with `GetTypes().` Should we go all-in on source generators, though? Is it worth moving code into a user's app and build processes over developers enjoying the separation?

Here's another consideration: is reflection just getting a bad rap? It can be slow for sure, but the .NET team has noted that performance is improving, and [there's a prototype they're working on making 10x faster](https://twitter.com/davidfowl/status/1389673507500351490).

It'll be interesting to see how far the .NET platform pushes on source generators over improving reflection performance. I'm guessing we'll see a little in Column A and a little in Column B. Everything is a tradeoff. Still, it's promising to see source generators shake up decades of thinking reflection is the only way to inspect types dynamically.

## IdentityServer templates shipping with .NET 6

Last December, IdentityServer [introduced a licensing model](https://blog.duendesoftware.com/posts/20201210_community_edition/) (and [we talked about it back in issue #20](https://www.daveabrock.com/2020/10/09/dotnet-stacks-20/)). You'll need to buy a license if your organization makes more than 1M USD/year (I know I have a global audience but believe me, you don't want me converting currency).

This week, Barry Dorrans announced that [.NET 6 will continue to ship these templates](https://devblogs.microsoft.com/aspnet/asp-net-core-6-and-authentication-servers/) (using the new RPL-licensed version). I personally applaud Microsoft's decision to continue to support IdentityServer, which is getting pushback from the blog's comments and [a super-spicy GitHub issue](https://github.com/dotnet/aspnetcore/issues/32494). A lot of the pushback comes from folks accusing IdentityServer of a "bait and switch"—as if profiting off free open-source software for a decade wasn't enough—and that Microsoft should build it themselves.

As Microsoft has said a bunch of times, and [bears repeating](https://github.com/dotnet/aspnetcore/issues/32494#issuecomment-834666754):

> As stated we are not authentication experts, we have no expertise in writing or maintaining an authentication server. We have a team at Microsoft dedicated to that, and they produce AAD. The .NET team will not be writing production ready authentication servers, both because of the cost in that and because in doing so it's likely we'll cannibalize users from existing open source projects, something the community was very vocal in wanting us not to do when the initial discussions around IdentityServer inclusion was started.

* * *

## 🌎 Last week in the .NET world

We have a lot of great community posts this week.

### 🔥 The Top 4

- Marc Gravell [asks: is the era of reflection-heavy C# libraries at an end?](https://blog.marcgravell.com/2021/05/is-era-of-reflection-heavy-c-libraries.html)
- Thomas Ardal [adds CAPTCHA on form posts with ASP.NET Core](https://blog.elmah.io/adding-captcha-on-form-posts-with-asp-net-core/).
- Charlin Agramonte [wires up a clearable time picker](https://xamgirl.com/clearable-time-picker-in-xamarin-forms/).
- Christopher Gill [announces README NuGet package support](https://devblogs.microsoft.com/nuget/add-a-readme-to-your-nuget-package).

### 📅 Community and events

- The .NET Foundation [provides its March/April update](https://dotnetfoundation.org/blog/2021/05/04/blog/posts/net-foundation-march-april-2021-update).
- JetBrains .NET Days Online [is happening this week](https://pages.jetbrains.com/dotnet-days-2021/dnf).
- The .NET Docs Show talks to Greg Cannon [about using .NET to build an e-ink dashboard for home automation](https://www.youtube.com/watch?v=t-rFj54BsDI).
- In community standups: ASP.NET [talks about minimal APIs](https://www.youtube.com/watch?v=enAskgcF0c0&t=4589s), Entity Framework [discusses triggers](https://www.youtube.com/watch?v=Gjys0Yebobk), and Xamarin [talks single-project architecture](https://www.youtube.com/watch?v=AQHZQ8p6FCA).

### 🕸 Web development

- Michael Shpilt [writes about ASP.NET server problems and solutions](https://michaelscodingspot.com/slow-asp-net-server/).
- Khalid Abuhakmeh introduces Razor [introduces Razor](https://khalidabuhakmeh.com/what-is-razor-aspnet).
- Chinedu Imoh [introduces JSON Web Tokens](https://www.telerik.com/blogs/introduction-json-web-tokens-jwt).
- Kristján Oddsson [writes how GitHub uses Web Components](https://github.blog/2021-05-04-how-we-use-web-components-at-github/).
- The Code Maze blog uses [the ProblemDetails class in ASP.NET Core Web API](https://code-maze.com/using-the-problemdetails-class-in-asp-net-core-web-api/).
- Damien Bowden [creates an OIDC credential issuer with Mattr and ASP.NET Core](https://damienbod.com/2021/05/03/create-an-oidc-credential-issuer-with-mattr-and-asp-net-core/).
- Jan Tattermusch [talks about grpc-dotnet](https://grpc.io/blog/grpc-csharp-future/).

### 🥅 The .NET platform

- The Packt blog [writes about upgrading existing .NET Apps to .NET 5](https://packt.medium.com/upgrading-existing-net-apps-to-net-5-e3768052ec44).
- Maarten Balliauw [builds a supply chain attack with .NET, NuGet, DNS, source generators, and more](https://blog.maartenballiauw.be/post/2021/05/05/building-a-supply-chain-attack-with-dotnet-nuget-dns-source-generators-and-more.html).

### ⛅ The cloud

- AWS announces [the end of support for AWS SDK for .NET version 2 (v2)](https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-aws-sdk-for-net-version-2-v2/).
- Lily Ma [writes about Azure Event Grid, Event Hubs, and Service Bus Library Improvements](https://devblogs.microsoft.com/azure-sdk/messaging-sdks).
- Daniel Krzyczkowski [continues writing about Azure Identity](https://daniel-krzyczkowski.github.io/Lost-In-Azure-Cloud-Identity-Serie-Part2/).
- Abhijit Jana [gets started with the Azure Web PubSub Service](https://dailydotnettips.com/getting-started-with-azure-web-pubsub-service/), then [creates a messaging app using Azure Web PubSub Service and C#](https://dailydotnettips.com/create-a-messaging-app-using-azure-web-pubsub-service-and-c/).

### 📔 Languages

- Ian Russell [uses alternate ways of creating single-case discriminated unions in F#](https://www.softwarepark.cc/blog/2021/5/1/alternate-ways-of-creating-single-case-discriminated-unions-in-f).
- Peter Vogel [writes about value objects in C# 9](https://visualstudiomagazine.com/articles/2021/04/07/csharp-9.aspx).
- Patrick Smacchia [writes about covariance and contravariance in C#](https://blog.ndepend.com/covariance-and-contravariance-in-csharp-explained/).
- Anthony Giretti [makes C# synchronous delegates asynchronous](https://anthonygiretti.com/2021/05/01/c-make-your-delegates-asynchronous-from-synchronous-delegates/).
- Andrew Lock [creates a simple moving average calculator](https://andrewlock.net/creating-a-simple-moving-average-calculator-in-csharp-1-a-simple-moving-average-calculator/).

### 🔧 Tools

- Abhijit Jana [writes about Visual Studio going 64-bit](https://dailydotnettips.com/visual-studio-2022/).
- Ali Ok [writes about Kubernetes configuration patterns](https://developers.redhat.com/blog/2021/05/05/kubernetes-configuration-patterns-part-2-patterns-for-kubernetes-controllers/).
- Anthony Giretti [generates an installation command for VS Code installed extensions](https://anthonygiretti.com/2021/05/06/visual-studio-code-did-you-know-you-can-generate-an-installation-command-of-your-installed-extensions/), and also [writes about Thunder Client, a way for you to work with APIs right in VS Code](https://anthonygiretti.com/2021/05/05/postman-i-love-you-but-i-met-thunder-client-for-visual-studio-code/).

### 📱 Xamarin

- Sam Basu [provides his weekly MAUI update](https://www.telerik.com/blogs/sands-of-maui-issue-7).
- Craig Dunn [creates dual-screen apps](https://devblogs.microsoft.com/surface-duo/dual-screen-xamarin-forms-animation).

### 🏗 Design, testing, and best practices

- Derek Comartin [unpacks the “event” term](https://codeopinion.com/event-based-architecture-what-do-you-mean-by-event/).
- Pieter Humphrey [writes about the value of serverless data APIs](https://www.infoq.com/articles/serverless-data-api/).
- Jon P. Smith [writes about evolving modular monoliths](https://www.thereformedprogrammer.net/evolving-modular-monoliths-1-an-architecture-for-net/).

### 🎤 Podcasts

- On the Software Engineering Podcast, [Daniel Roth talks about Blazor](https://www.se-radio.net/2021/05/episode-458-daniel-roth-on-blazor/).
- Serverless Chats [talks about multi-cloud](https://www.serverlesschats.com/99/).
- The Azure Podcast [talks to David Giard about Azure Media Services](http://azpodcast.azurewebsites.net/post/Episode-376-Azure-Media-Services).

### 🎥 Videos

- Azure Friday [talks about the Azure Resource Mover](https://channel9.msdn.com/Shows/Azure-Friday/Simplify-moving-resources-between-regions-with-Azure-Resource-Mover).
- The Xamarin Show [builds accessible mobile apps](https://channel9.msdn.com/Shows/XamarinShow/Building-Accessible-Mobile-Apps--The-Xamarin-Show).
- The Visual Studio Toolbox [talks about EF Core](https://channel9.msdn.com/Shows/Visual-Studio-Toolbox).
- The DevOps Lab [talks about cloud security](https://channel9.msdn.com/Shows/DevOps-Lab/On-Prem-To-The-Cloud-Security-is-Not-an-Afterthought-episode-9).
- The On .NET Show [talks about tuple pattern matching C#](https://channel9.msdn.com/Shows/On-NET/C-Language-Highlights-Tuple-Pattern-Matching), [uses Azure managed identities](https://www.youtube.com/watch?v=vYUKC0mZFqI), and [adds machine learning to .NET apps with ML.NET](https://www.youtube.com/watch?v=THVD4nzi8vk).