简体   繁体   中英

C# to VB.net error of is not defined

In C# its this:

Imports System.Runtime.Serialization

.....
[DataContract]
public class erUser : SerializedJson<erUser>
{
    [DataMember(Name = "id")]
    public string UserID { get; set; }

Converting that to VB.net above gets me this:

<DataContract()> _
Public Class erUser
    Inherits SerializedJson(Of erUser)
    <DataMember(Name:="id")> _

Which gives me errors on the DataContract() and also DataMember .

The error is:

Type 'DataMember' is not defined. Type 'DataContract' is not defined.

How can i fix this since im not an all-out C# programmer? :)

Both DataContractAttribute and DataMemberAttribute are found in System.Runtime.Serialization , as can be seen from the documentation links above.

So, import that namespace:

Imports System.Runtime.Serialization

Of course, you could omit that and use fully qualified names:

<System.Runtime.Serialization.DataContract()> _
...

But that's not a whole lot of fun, so I do suggest that you import the namespace.

The other possible failure mode is that you have not added a reference to the assembly that implements these types. For both of these types that assembly is System.Runtime.Serialization .


As a general rule, when you encounter an error like this, you need to find the documentation of the name that cannot be resolved, and that documentation will tell you which namespace you need to import. For .net framework the information looks like this:

Inheritance Hierarchy

\nSystem.Object     \n  System.Attribute \n    System.Runtime.Serialization.DataMemberAttribute  \n

Namespace : System.Runtime.Serialization
Assembly : System.Runtime.Serialization (in System.Runtime.Serialization.dll)

The key information is here. As well as the namespace that you need to import, there is the assembly which implements the functionality. You must make sure that you reference any assemblies that you need to use.

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