简体   繁体   中英

xxxxx is a namespace but is used like a Type

I have an issue that seems to give a large number of hits when searching on SO however every single instance I have read is clear that the poster actually is creating a namespace using a name they then go on to use again as a Class etc.

I have an instance where I cannot find any reference to the namespace it claims I am mis-using.

I am using VS 2017 co-writing a .net core 2 app and getting the above issue. The strange thing is that if I push the code to TFS and my colleague then pulls it down he does not get the issue. If I wipe my copy and pull down a fresh copy myself I still get the issue.

ChangeFormViewModel.cs

using ChangeRequestForm_Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChangeRequestForm_Web.ViewModels
{
    public class ChangeFormViewModel
    {
        public ChangeRequest ChangeRequest { get; set; }
        public ChangeProfile ChangeProfile { get; set; }

        public List<ChangeDataItem> ChangeDataItems { get; set; }
    }
}

The offending line is;

public ChangeRequest ChangeRequest { get; set; }

ChangeRequest.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace ChangeRequestForm_Data.Models
{
    public class ChangeRequest : BaseEntity
    {
        public string ChangeTitle { get; set; }
        public bool ChangeSubmitted { get; set; }
        public bool ChangeCompleted { get; set; }

    }
}

I have checked my installation of VS and verified that I am also using the same version as my colleague. This has occured over two different projects now.

EDIT: If I use ChangeRequestForm_Data.Models.ChangeRequest this works and is in fact how I got around the issue in the previous project. When my colleague then pulls my changes he then gets highlighting within VS suggesting it could be optimised as the full reference is un-neccessary.

尝试使用完全限定名称

public ChangeRequestForm_Data.Models.ChangeRequest ChangeRequest { get; set; } 

您需要在模型类定义之前正确设置项目的命名空间,不需要完全限定名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM