找不到类型或命名空间名称 'ProtoContractAttribute'
The type or namespace name 'ProtoContractAttribute' could not be found
我正在尝试测试 Protobuf-net 并在尝试构建项目时遇到上述错误(以及其他几个错误 'ProtoContract'、'ProtoMember'、'ProtoMemberAttribute'找不到)。我已确保项目中安装了 protobuf-net,并尝试了所有可能的 Protobuf 使用语句(编译器、Meta 和序列化程序),但它仍然无法构建。以下是我的代码:
[ProtoContract]
public class TestClass
{
#region fields
[ProtoMember(1)]
public string name;
[ProtoMember(2)]
public object value;
[ProtoMember(3)]
public object xFValue;
#endregion
public TestClass();
}
此外,我使用的是 .NET 4.5.2
对发生的事情有什么想法吗?谢谢!
编辑:正如 maccettura 在下面所说的,问题是我没有包含语句 "using Protobuf;"
正如 maccetura 在评论中所说,问题是我没有包含语句 "using Protobuf;" 现在似乎可以编译。
您很可能忘记包含适当的 using
指令。
根据文档,ProtoContract
位于 "ProtoBuf" 命名空间中,所以试试这个:
using ProtoBuf;
这应该可以解决您的问题。
我正在尝试测试 Protobuf-net 并在尝试构建项目时遇到上述错误(以及其他几个错误 'ProtoContract'、'ProtoMember'、'ProtoMemberAttribute'找不到)。我已确保项目中安装了 protobuf-net,并尝试了所有可能的 Protobuf 使用语句(编译器、Meta 和序列化程序),但它仍然无法构建。以下是我的代码:
[ProtoContract]
public class TestClass
{
#region fields
[ProtoMember(1)]
public string name;
[ProtoMember(2)]
public object value;
[ProtoMember(3)]
public object xFValue;
#endregion
public TestClass();
}
此外,我使用的是 .NET 4.5.2
对发生的事情有什么想法吗?谢谢!
编辑:正如 maccettura 在下面所说的,问题是我没有包含语句 "using Protobuf;"
正如 maccetura 在评论中所说,问题是我没有包含语句 "using Protobuf;" 现在似乎可以编译。
您很可能忘记包含适当的 using
指令。
根据文档,ProtoContract
位于 "ProtoBuf" 命名空间中,所以试试这个:
using ProtoBuf;
这应该可以解决您的问题。