English 中文(简体)
protobuf-net [de]serializing across assembly boundaries
原标题:

I have a base class in one assembly and a large number of generated classes in another that inherit from the base class. Using protobuf-net (r282) to serialize a list of the base type fails when attempting to resolve the subclassType (line 248 of SerializerT.cs) because the subclass is not in the assembly of the base class. Moving the classes together is not a preferred option and it is rather important that I can pass around List.

Here is my tagged base class. The included types are marked with ProtoMember(x) as required.

[ProtoContract] 
[ProtoInclude(1,"SomeItemType")]
[ProtoInclude(2,"AnotherItemType")]
[ProtoInclude(190,"YetAnotherItemType")]
public abstract class BaseItem
{
}

As a side note, this is part of evaluating using protobuf-net to replace BinaryFormatter for moving data between a desktop app and a SOAP webservice.

Can I do this sort of thing at all? Is there a better way? Am I just missing something obvious? A separate longer term question is should I be doing anything slightly different to prepare for an eventual move to 3.5?

最佳回答

Perhaps the easiest way to use ProtoInclude is with typeof, since this will handle a lot of the nuances for you automatically:

[ProtoInclude(1, typeof(SomeItemType))]

Alternatively you can just use assembly-qualified names, so:

[ProtoInclude(1,"SomeItemType, SomeRandomAssembly")]

In a rather peculiar case involving multiple AppDomains, I ve found you can also work some magic with the AppDomain.TypeResolve event, but that should be avoided if possible. I also have a complete re-working of the metadata layer in the pipeline, allowing much more flexibility at runtime (rather than having to declare everthing at compile, which is causing some of the pain above).

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签