What in tarnation (and tarnation accessories)

Fixing unexpected Microsoft.AspNetCore package errors after a dependency update

This post was most recently updated on February 19th, 2021.

2 min read.

This was a fun one! Suddenly, while running or debugging my ASP.NET Core 3.1 application, I started getting errors about missing assemblies, along the lines of “FileNotFoundException: Could not load file or assembly Microsoft.AspNetCore.Components.Forms“. These DLL files were not required a minute earlier – nor did requiring them really make much sense in my mind – but there was a nonsensical, easy fix, so in the end it was all good!

But let’s go through this thing in order. What was the problem now?


Table of Contents

So, this was the error I was running into, whenever I ran or debugged my app:

FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Components.Forms, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

The weird part was that I didn’t even need this dependency before I updated Microsoft.AspNetCore.Componentsfrom to! Not sure if this was a breaking change in the dependency or something different.

A similar error occurred for another package, Microsoft.AspNetCore.Components.Web.

In that case, the issue was slightly different as I did in fact have the package already referenced – it just stopped working :)

Anyway, let’s go through the fix next.


You need to add the dependency, and (weirdly enough) tell it to include private assets. And here’s how you can do that!

Time needed: 5 minutes.

How to fix missing assets from your precious dependencies?

  1. Open your .csproj file in edit mode

    Just right-click your project in the Solution Explorer – like below:
    "Edit Project File" in Visual Studio Solution Explorer

  2. Add your dependency

    Obviously, this step is only required if your dependency is in fact missing! I got this error for 2 dependencies, one was missing from the .csproj file, the other one wasn’t.

    I already had a reference to Microsoft.AspNetCore.Components, and I had to add Microsoft.AspNetCore.Components.Forms as well.

  3. Modify the XML for your problematic package(s)

    For whatever reason, you need to add <PrivateAssets>All</PrivateAssets> to your package reference.

    The XML should look somewhat like this:

    <PackageReference Include="Microsoft.AspNetCore.Components.Forms" Version="3.1.10">

    This needs to be done for each problematic package.

  4. Rebuild and you should be good!

    And after that, if you get another error – about another package, most likely – just rinse and repeat for each one that’s giving you trouble.

  5. (Optional) Remove the <PrivateAssets> -part

    At this point, for whatever reason, you should be able to remove the newly added XML node.

    You can probably even remove any new dependencies you had to add!

Another surprising error, another weird fix. But did it work for you? Let me know in the comments below! :)

5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments