This was a fun one! Suddenly, while running or debugging my ASP.NET Core 3.1 application, I started getting errors about missing assemblies. 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=126.96.36.199, 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 188.8.131.52 to 184.108.40.206! 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! :)
- How to fix “System.IO.FileSystem: Could not find a part of the path \AppData\Local\AzureFunctionsTools\Releases\3.17.0\workers. Value cannot be null. (Parameter ‘provider’)” when running Azure Functions locally? - January 12, 2021
- How to nuke the Identity Cache in Visual Studio? - January 11, 2021
- Fixing unexpected Microsoft.AspNetCore package errors after a dependency update - January 6, 2021