This post was most recently updated on September 25th, 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?
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=18.104.22.168, 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 22.214.171.124 to 126.96.36.199! 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.
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?
- Open your .csproj file in edit mode
Just right-click your project in the Solution Explorer – like below:
- 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.
- 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.
- 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.
- (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! :)
- How to install Home Assistant on Synology NAS (DSM 7.2)? - August 29, 2023
- How to configure a custom 404 page for a SharePoint site? - August 22, 2023
- Azure DevOps pipelines suddenly failing with “##[error]#0 building with default instance using docker driver” - August 15, 2023