user3096803
user3096803

Reputation:

New .Net Core Library Serialization Attributes Not Working

I'm trying to extract some classes from an MVC project into their own .Net Core class library in the same solution. So far, I have added this class to the new class library:

[DataContract]
public class EmailStatusNotification
{
    [DataMember(Name = "nothing_interesting")]
    public string TestProp { get; set; }
}

[DataContract] displays an error :

Cannot apply attribute class DataContract because it is abstract.

[DataMember] displays an error :

The type Object is defined in an assembly that is not referenced. You must add a reference to assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

What is likely the cause of this? I have not removed any dependencies from the project.

Upvotes: 2

Views: 1364

Answers (2)

fullhalfie
fullhalfie

Reputation: 41

I was running into the exact same problem with [DataContract] and [DataMember]. It turns out that there was an extra assembly reference to System.Runtime.Serialization that was causing some ambiguity when trying to use the DataContractAttribute. Removing the assembly reference fixed the error. I suspect that one of the times you recreated the library you also cleared the references.

Upvotes: 4

user3096803
user3096803

Reputation:

I recreated the class library in the exact same way for the 5th or 6th time and it miraculously started working. I'm almost positive that this was a bug/feature of Visual Studio, but I don't even know how to go about reporting it as it's so abstract.

Upvotes: 0

Related Questions