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?
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=184.108.40.206, 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 220.127.116.11 to 18.104.22.168! 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?
- 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! :)
- HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core? - July 27, 2021
- Docker-compose fails on Windows with “Error while fetching server API version: (2, ‘CreateFile’, ‘The system cannot find the file specified.’)” - July 20, 2021
- Azure DevOps suddenly 404s for your project? Easy fix! - July 13, 2021