Default Blazor WebAssembly App doesn't compile - blazor-webassembly

I am using Visual Studio 2022, .Net Core 6.0.200 SDK and runtimes are installed.
I create a new Blazor WebAssembly App via VS.
I build it.
And it fails with this error:
error CS0246: The type or namespace name 'TestBlazorApp1' could not be found (are you missing a using directive or an assembly reference?)
TestBlazorApp1 is the name of the project.
It doesn't make any sense...there's just the one assembly so how can it not find that reference?

Related

Blazor WebAssembly .NET6 upgrade to .NET7 causes JS module error

I have an existing Blazor project that has target framework set to .NET 6.0.
After installing Visual Studio 17.4.1 and setting the target framework to .NET 7.0, I get a runtime error:
Uncaught SyntaxError: Cannot use 'import.meta' outside a module (at dotnet..3611wiw0dy.js:8:27)
What should I set to make it work?
You may need to upgrade your nuget packages to version 7.0
Eg.:
Microsoft.AspNetCore.Components.WebAssembly
Microsoft.AspNetCore.Components.WebAssembly.DevServer
Microsoft.AspNetCore.Components.Authorization
Microsoft.Extensions

I have Installed Newtonsoft.Json from manage Nuget packages in Visual studio yet I get The type or namespace name 'Newtonsoft' could not be found

I have downloaded a tutorial file in which the tutor is explaing how to use Moralis to connect a wallet to a Unity game. However in many of the scripts it needs to use Newtonesoft.Json which apparently it can't.
I have already installed Newtonsoft.Json using NuGet package manager in Visual studio both in version 2022 and 2019. But yet I get this error.
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp D:\work\UNITY\Moralis test2\Moralis test2\Assets\MoralisWeb3ApiSdk\Moralis\Moralis.Web3Api.Core\Models\NftTransfer.cs 6 Active
enter image description here

How to build net core 3.0 app using VS 2019

I want to compile a .net project using net core 3, in the hope that it will then run on the latest Ubuntu.
I have downloaded VS2019, and the net core 3 SDK, and enabled previews in Tools/Options/Environment/Preview features.
I created a new project (it defaulted to net core 3.0), added some source files, and tried to build it.
I got these errors:
1>------ Build started: Project: BaseCampApi, Configuration: Debug Any CPU ------
1>C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>c:\dev\BaseCampApi\BaseCampApi\BasecampApi.cs(18,17,18,27): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
1>c:\dev\BaseCampApi\BaseCampApi\BasecampApi.cs(303,17,303,49): error CS0246: The type or namespace name 'FileExtensionContentTypeProvider' could not be found (are you missing a using directive or an assembly reference?)
1>Done building project "BaseCampApi.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What do I do to get it to compile?
Did you restore all dependencies?
Try running dotnet restore and then dotnet build if you're using the terminal or just Nuget Restore through VS.
If it doesn't help, you'll have to remove some artifacts from the .csproj file and restore dependencies after that. Look for something like:
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Core">
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.core\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
</Reference>
</ItemGroup>
Remove it and reference it anew by restoring with Nuget.
Also, make sure you're actually in an ASP.NET project and not a console one, for example. Your project is called "*Api" which in the general case should mean that it is an ASP.NET project indeed but you never know.
EDIT after comments:
So, it turned out you have a Console application after all and you're referencing packets from ASP.NET. Either create a new ASP.NET Web App and move your code there or include the framework packets(if you need them that much AND if they're actually compatible considering the task in hand). Most probably there should be an alternative ones for console applications, though, so you should use them instead).

How to properly add DateTime to DotNet Core application?

I use ubuntu:
I run: $ dotnet run
I get error:
The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)
How can I add DateTime namespace in dotnet CORE app?

from 4.5 to 4.0 :The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft'

I was working on .Net 4.5 used SignalR 1.1.2 and everything works fine.
Then we want to lower the version of netframework to 4.0 cos of production server, everything stopped and this error appeared. Please tell me what to do?
The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Solved problem by removing reference from project then build. After failed Build Add reference. Working perfectly in .net 4.0.
We can also Uninstall then install nuGet Packages.
Solved by deleting the contents of bin and obj folder on my project folder, then open the project and rebuild.

Resources