P
P
Piligr1m2015-12-03 12:36:41
C++ / C#
Piligr1m, 2015-12-03 12:36:41

How to serialize a class field that is an object described in another assembly (dll)?

I am using Microsoft.CodeAnalysis.CSharp.dll in my project. I have a class, the property of this class is an object that was described in Microsoft.CodeAnalysis.CSharp.dll and connected to my project.

[ProtoContract]
public class FunctionAnnotation : 
{
     [ProtoMember(1)] public IMethodSymbol Symbol { get; set; }
}

IMethodSymbol is described in Microsoft.CodeAnalysis.CSharp.dll . I am using protobuf-net. When trying to serialize an object, it throws an exception:
No serializer defined for type: Microsoft.CodeAnalysis.IMetnodSymbol.

It is clear that Microsoft.CodeAnalysis.IMetnodSymbol is not marked as [ProtoContract] .
private void Serialization()
{
     string folderName = @"f:/serialization/";
     Directory.CreateDirectory(folderName);
     int name = this.Symbol.ToString().GetHashCode();
     using (FileStream fs = new FileStream("f:/serialization/" + name + ".dat", FileMode.OpenOrCreate))
     {
          Serializer.Serialize(fs, this);
     }
}

How to solve this problem? Are there options to not manually tag classes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MonkAlex, 2015-12-03
@MonkAlex

You can try to create a child of the desired class and work with it, but I suspect protobuf has better solutions. Have you tried google?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question