I am trying to swap a BinaryFormatter implementation with protobuf-net. The use case is to be able to serialize and deserialize the NHibernate.Configuration object. The "configuration" object is complex and we have no ability to decorate it with attributes. We add the type to the runtime type model however the object isn't being serialized (file is 0 bytes).
First I added the Configuration type to the runtime type model:
model.Add(typeof(NHibernate.Cfg.Configuration), false)
That didn't work so I added all the properties:
model.Add(typeof(NHibernate.Cfg.Configuration), false)
.Add("ClassMappings",
"CollectionMappings",
"EntityNotFoundDelegate",
"EventListeners",
"Imports",
"Interceptor",
"NamedQueries",
"NamedSQLQueries",
"NamingStrategy",
"Properties",
"SqlFunctions",
"SqlResultSetMappings");
That still didn't work as I now receive errors such as:
No serializer defined for type: NHibernate.Mapping.PersistentClass
Do I need to add the NHibernate.Mapping.PersistentClass to the runtime type model? If so, is it mapped as a subtype or a second type. Compiling the project results in similar errors for all the following types:
RuntimeTypeModel.Default.Add(typeof(NHibernate.IInterceptor), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Mapping.RootClass), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Mapping.Collection), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Cfg.INamingStrategy), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Event.EventListeners), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Mapping.PersistentClass), false);
RuntimeTypeModel.Default.Add(typeof(NHibernate.Proxy.IEntityNotFoundDelegate), false);
Adding these types to the runtime type model doesn't work. Errors are still raised during compilation, most notably a "subtype not known" however the exception does not tell me which type the object is a subtype of.
Is there an easier way to get protobuf-net to serialize/deserialize a 3rd party object of unknown complexity?
The motivation for this question is to replace BinaryFormatter in the following use case:
Speed Up nHibernate Startup With Object Serialization