Ошибка cs0246 не удалось найти тип или имя пространства имен

I have the following errors (and more) in all my views (*.cshtml) when opening my project in Visual Studio 2015 Professional.

Error CS0246 The type or namespace name ‘System’ could not be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line

Error CS0518 Predefined type ‘System.Object’ is not defined or imported
Severity Code Description Project File Line

Error CS0518 Predefined type ‘System.String’ is not defined or imported

I got these references:

<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSitecore.Kernel.dll</HintPath>
</Reference>
<Reference Include="Sitecore.Mvc">
  <HintPath>N:XXXSitecore.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Providers">
  <HintPath>N:XXXSystem.Web.Providers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:XXXSystem.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />

I found some solutions saying that a mscorlib wasn’t referenced.. but when I tried to add it it sayd that it’s already there (even though I don’t see it on the csproj file).

System.dll reference:

enter image description here

enter image description here

SOLUTION:

Managed the issue.. I had the build path set to a «c:…bin» instead of «bin». I believe this happened because I don’t have any web.config in the root of the project, so VS didn’t identify my project as a web project.

I am using Snarl C# API to send notifications to snarl.

Now I have saved the content of above url in a file named SnarlNetwork.cs and the content of my test.cs file are:

using SnarlNetworkProtocol;
using System;
class test
{
    public static void Main(String[] args)
    {
        SNP snarl_object = new SNP();
        string hostname = "localhost";
        string hostport = "9887";
        string appName = "Spotify";

        bool val = snarl_object.register(hostname, hostport, appName);

        if (val == true)
        {
            string title = "hello";
            string message = "world";
            string timeout = "5";
            bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);

            if (newval == true)
            {
                Console.WriteLine("sucessfull");

            }
        }
    }

}

Now when I try to compile my test.cs file using csc test.cs I get the following error:

C:UsersNoobcsharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)

So, what am I doing wrong here because according to me I am not missing any using directive.

Студворк — интернет-сервис помощи студентам

Добрый день!
Я еще новичок в программировании , потихоньку изучаю С# решил попробовать что- то написать , но столкнулся с непонятной ошибкой . скриншот прилагаю , задавал вопрос другим программистам , на что получил ответ : «Я такое за 10 лет вижу впервые» , Друзья , товарищи подскажите что сделать как быть , в крайнем случае куда пойти))

Итак , в первом проекте ошибок на System нету , когда добавил второй проект , чтобы там что-то еще написать появляется эта чудесная ошибка и как быть хз.
П.С студию сносил полностью в том числе чистил реестр , обновлял , удалял заного и ставил опять и так три раза — переустановка не помогает ….

Подскажите люди добрые…

C# Compiler Error

CS0246 – The type or namespace name ‘type/namespace’ could not be found (are you missing a using directive or an assembly reference?)

Reason for the Error

You will most likely receive this error when the C# compiler has not found the type or the namespace that is used in your C# program.

There are plenty of reasons why you will have this error code from C#. These include

  • You have missed adding reference to the assembly that contains the type.
  • You have missed adding the required using directive.
  • You could have misspell the name of the type or namespace.
  • You would have referenced an assembly that was built against a higher .NET framework version than the target version of the current program.

For example, try compiling the below code snippet.

using System;
namespace DeveloperPubNamespace
{
   class Program
    {

        public static void Main()
        {
            var lstData = new List<int>();
        }
    }
}

This program will result with the C# error code CS0246 because you are using the type List but is not fully qualified or the using directive is not applied in the program for the namespace where the List exists.

Error CS0246 The type or namespace name ‘List<>’ could not be found (are you missing a using directive or an assembly reference?) DeveloperPublish C:UsersSenthilBalusourcereposConsoleApp3ConsoleApp3Program.cs 9 Active

C# Error CS0246 – The type or namespace name 'type/namespace' could not be found

Solution

You can fix this error in C# by ensuring that you add the right type or namespace in your program. Ensure that you have used the using directive to include the namespace or atleast using the fully qualified name for the class as shown below.

namespace DeveloperPubNamespace
{
   class Program
    {

        public static void Main()
        {
            var lstData = new System.Collections.Generic.List<int>();
        }
    }
}

В редакторе кода подвести мышку с проблемной строки и искать значок с подсказкой по устранению её.
Либо вручную добить сборку в проект где этот класс NavMeshAgent объявлен, и указать его namespace в using.

Ответ написан

более трёх лет назад


Комментировать

Возможно, вам также будет интересно:

  • Ошибка cs0161 не все пути к коду возвращают значение
  • Ошибка cs0121 неоднозначный вызов следующих методов или свойств
  • Ошибка cs0120 для нестатического поля метода или свойства требуется ссылка на объект
  • Ошибка cs0115 form1 dispose bool не найден метод пригодный для переопределения
  • Ошибка cs0106 модификатор public недопустим для этого элемента

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии