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?
Related
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?
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).
In my nugent panel, I installed
AutoMapper v7.0.1
AutoMapper.extensions.microsoft.dependencyinjection v5.0.1
In my Startup.cs,
I added
Services.AddAutoMapper();
but the compiler gives
Severity Code Description Project File Line Suppression State
Error CS1061 'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) OPEApiService J:\Projects\OPEApiService\OPEApiService\Startup.cs 58 Active
I tried clean, rebuild, close and reopen VS.
Any help is appreciated.
Thanks
This could be a compatibility issue between the two packages.
If you have both the AutoMapper and AutoMapper.extensions.microsoft.dependencyinjection packages installed, remove them and add only the AutoMapper.extensions.microsoft.dependencyinjection. It has a dependency on the AutoMapper package.
I had this same issue and was able to resolve it.
You missed the restore step. From the root directory where the solution file exists, run following command:
dotnet clean
dotnet restore
dotnet build
Build error I received after including the services.AddAutoMapper();
Then after executing the series of command, got it running.
You need to add a reference to :
$ AutoMapper.Extensions.Microsoft.DependencyInjection
Search it using NuGet Packages Manager and install it.
I'm trying to use CssRewriteUrlTransform but am having a problem referencing it.
I updated to the latest Microsoft.AspNet.Web.Optimization using package manager:
update-Package Microsoft.AspNet.Web.Optimization -reinstall
And can now see System.Web.Optimization v4.0.30319 referenced in my project.
However I'm still getting
Error 19 The type or namespace name 'CssRewriteUrlTransform' could not
be found (are you missing a using directive or an assembly
reference?)
Is there something else I'm missing?
(I've got using System.Web.Optimization;)
VS Cannot 'resolve' the issue.
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.