I have been working through an awesome tutorial within Udemy to learn more about Blazor (https://www.udemy.com/course/programming-in-blazor-aspnet-core/), but have hit a stumbling block that I'm not entirely sure what to do with.
Short Version
When upgrading to .Net 5 from .Net Standard 2.1, I end up with this error when trying to run this sample Blazor application as soon as it loads up (so it's not hitting any of my code): System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
I see a similar problem with this SO link, but it didn't really give me much to go off of.
Detailed Version
With prior versions of .Net, you installed the latest, then Visual Studio picked that up, you switched projects and away you went - everything was seamless and just worked. With some of the newer stuff though, Microsoft's messaging has been extremely confusing and the problem I'm hitting now is inside that Udemy tutorial I need to utilize the IJSObjectReference
interface to do something. When I first added that to the code, the type reference couldn't be resolved so a quick search pointed me to needing to move the project to .Net 5 by changing this:
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
to this (because Visual Studio doesn't always show .Net 5 as an option):
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
Seemed simple enough, so I changed the Client Blazor project to this and tried to compile. That gives me this error: Project BlazorMovies.Client is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project BlazorMovies.Client supports: net5.0 (.NETCoreApp,Version=v5.0)
. I figured okay, I'll bump Server to 5.0 next and then everything compiles fine, but as soon as I pull it up, I get this error: System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
. Then I remembered not recalling if I'd installed .Net 5 yet, so I went to check and (via docs.microsoft.com) I only have 4.8.03752 installed. I then did some searches to try and find the .Net installers and there were multiple (see here) - even the layout of the page is really overwhelming, with ~20 install links scattered throughout. I knew I needed at least x64, so I first installed the SDK since it said Visual Studio support and that went significantly faster than I expected (based on prior installs of .Net), but now VS is showing .Net 5 which seemed promising! I re-checked the registry though, and it still says 4.8.03752 and when I went to Add/Remove programs, .Net 5 doesn't show up like all the other versions. I next installed the Hosting Bundle which said it was successful, but the sample app still has the exact same error.
Any advice? I know Blazor is quite new, but with Microsoft's extremely confusing messaging between .Net Framework, .Net Standard, .Net Core and now a migration back into .Net 5 that seems to need multiple installers, I don't really know where to go next. That error is entirely generated from within the Web Assembly code according to the stack trace, so it doesn't appear to be anything related to what I'm doing. Here's a screenshot of everything Chrome shows me in the console: