I am using protobuf-net for my protocol buffering. I have a dll I am loading dynamically. I can create an instance of a data class contained within the dll, and I can use and modify the created data object. However, When I attempt to serialize/deserialize the data object I get the following crash:
{"Unable to identify known-type for ProtoIncludeAttribute: MyDataDLL.MyDataClass, MyDataDLL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"}
and sometimes a crash saying that MyDataClass is not a subclass of MyBaseClass, or something like that. MyDataClass definitely inherits from MyBaseClass, and MyBaseClass has a ProtoInclude tag for MyDataClass .
Assembly theAssembly = Assembly.LoadFrom("MyDataDLL.dll");
Type theType = theAssembly.GetType("MyDataDLL.MyDataClass");
object theData = Activator.CreateInstance(theType);
using (FileStream theStream = File.Open(fileName, FileMode.OpenOrCreate))
{
MethodInfo method = typeof(ProtoBuf.Serializer).GetMethod("Deserialize").MakeGenericMethod(theType);
theData = method.Invoke(null, new object[] { theStream });
}
The crash happens on "method.invoke"
If I reference the dll in the project and use it that way, I don't get the crash. So I know it is a working dll.
Update: Yes, MyDataClass and MyBaseClass are in the same assembly.
Here's a list of what my code does differently then your test class, though it's probably not extensive: MyDataClass is the 4th in a list of 7 ProtoIncludes.
MyBaseClass contains all the data fields, MyDataClass contains the logic for functions that manipulate these data fields. So there are no ProtoMember calls in MyDataClass.
MyBaseClass implements the IExtensible interface and has the following function to handle additional data:
private ProtoBuf.IExtension extensionObject;
ProtoBuf.IExtension ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) {
return ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing);
}
Its probably not affecting anything, but my ProtoContracts use the Name parameter.