TypeModel.DeserializeType(value) Exception Message request.

54 views
Skip to first unread message

Lex

unread,
Oct 11, 2011, 4:38:41 AM10/11/11
to Protocol Buffers
Hi,

We have recently started using protobuf-net for some serialization
tasks that we have. Our particular problem is that our serialized
objects can live for possibly weeks at a time before we need to de-
serialize them. In the mean time we may need to re-factor some of the
namespaces of the nested objects in the serialized objects.

After a bout of re-factoring I ran the de-serialization and got a
'Null reference' exception message. With no more information to work
with I had to check the source code out and debug it to find the
offended code. Once found I attached a handler to
TypeModel.DynamicTypeFormatting to fix our issue which works very
nicely.

However I feel it would be very nice if we could have a better
exception message output so it could tell me what string it was trying
to get a type for a failed. Maybe checking the result of the call to
model.DeserializeType in ProtoReader.DeserializeType for null and
throwing an exception that outputs the Assembly name so that we know
what it failed to find a type for.

For your consideration,

Lex

Marc Gravell

unread,
Oct 11, 2011, 2:17:59 PM10/11/11
to Lex, Protocol Buffers
In standard use, protouf-net is fully contract based and doesn't care what *types* are involved; this only matters if you are using the DynamicType option (which is outside the core protobuf stuff). If the types aren't stable, there is an event on the TypeModel that can be used to map in both directions between strings/Types - the default is to use AssemblyQualifiedName, but you can use anything you like as long as you can provide a robust map between strings and types.

Does that help?

> --
> You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
> To post to this group, send email to prot...@googlegroups.com.
> To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
>

Marc Gravell

unread,
Oct 12, 2011, 5:41:50 AM10/12/11
to Protocol Buffers
In the next build, this has been tweaked:

type = source.DeserializeType(typeName);
if(type == null)
{
throw new ProtoException("Unable to
resolve type: " + typeName);
}

So, this should be resolved from then.

Thanks for the (very valid) suggestion,

Marc

Lex

unread,
Oct 12, 2011, 5:44:22 AM10/12/11
to Protocol Buffers
Thanks Marc, that's great news :)
> > Lex- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages