简体   繁体   中英

The type or namespace name 'Name' could not be found

The type or namespace name 'Question'could not be found (are you missing a using directive or an assembly reference?)

I've spent the morning reading threads with the same error, but haven't found anything that seems to apply. The references seem to be set up correctly. I tried adding "using TestProject.Trivia.Web", but then I just get "The type or namespace name 'Web' does not exist in the namespace 'TestProject.Trivia' (are youmissing an assembly reference?).

In one project, I have this cs file:

using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace TestProject.Trivia
{
[DataContract]
public class Course
{
    [XmlAttribute, DataMember]
    public string Name { get; set; }

    [XmlAttribute, DataMember]
    public int Id { get; set; }

    [XmlElement, DataMember]
    public Question [] Questions { get; set; }
}

}

It has a reference to class TestProject.Trivia.Web, which has a javascript file with the definition of a question (which I'm referencing in the rest of the solution with no trouble).

Any ideas will be appreciated...

Defining Question is a javascript file does not create an object of Question in .Net, so you cannot use it as a .Net object in the C# code.

Make a class Question and use that.

public class Question
{
    ...
}

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