@@ -120,6 +120,19 @@ public bool TryEmitDeserialiseCode(ILGenerator ilg, ThrowBlockGatherer throwBloc
120120 ilg . Emit ( OpCodes . Throw ) ;
121121 } ;
122122
123+ Action loadPeekedFormatName = ( ) =>
124+ {
125+ var format = ilg . DeclareLocal ( typeof ( Format ) ) ;
126+ ilg . Emit ( OpCodes . Ldloc , unpacker ) ;
127+ ilg . Emit ( OpCodes . Ldloca , format ) ;
128+ ilg . Emit ( OpCodes . Call , Methods . Unpacker_TryPeekFormat ) ;
129+ // Drop the return value: if false, 'format' will be 'Unknown' which is fine.
130+ ilg . Emit ( OpCodes . Pop ) ;
131+ ilg . Emit ( OpCodes . Ldloc , format ) ;
132+ ilg . Emit ( OpCodes . Box , typeof ( Format ) ) ;
133+ ilg . Emit ( OpCodes . Call , Methods . Format_ToString ) ;
134+ } ;
135+
123136 #region Initialise locals for constructor args
124137
125138 var valueLocals = new LocalBuilder [ parameters . Length ] ;
@@ -204,7 +217,9 @@ public bool TryEmitDeserialiseCode(ILGenerator ilg, ThrowBlockGatherer throwBloc
204217 ilg . Emit ( OpCodes . Ldstr , "Data stream empty" ) ;
205218 throwException ( ) ;
206219 ilg . MarkLabel ( lblNotEmpty ) ;
207- ilg . Emit ( OpCodes . Ldstr , "Message must be encoded as a MsgPack map" ) ;
220+ ilg . Emit ( OpCodes . Ldstr , "Message must be encoded as a MsgPack map, not \" {0}\" ." ) ;
221+ loadPeekedFormatName ( ) ;
222+ ilg . Emit ( OpCodes . Call , Methods . String_Format_String_Object ) ;
208223 throwException ( ) ;
209224 } ) ;
210225 }
@@ -325,18 +340,9 @@ public bool TryEmitDeserialiseCode(ILGenerator ilg, ThrowBlockGatherer throwBloc
325340 {
326341 throwBlocks . Throw ( ( ) =>
327342 {
328- var format = ilg . DeclareLocal ( typeof ( Format ) ) ;
329- ilg . Emit ( OpCodes . Ldloc , unpacker ) ;
330- ilg . Emit ( OpCodes . Ldloca , format ) ;
331- ilg . Emit ( OpCodes . Call , Methods . Unpacker_TryPeekFormat ) ;
332- // Drop the return value: if false, 'format' will be 'Unknown' which is fine.
333- ilg . Emit ( OpCodes . Pop ) ;
334-
335343 ilg . Emit ( OpCodes . Ldstr , "Encountered unexpected field \" {0}\" of MsgPack format \" {1}\" for CLR type \" {2}\" ." ) ;
336344 ilg . Emit ( OpCodes . Ldloc , key ) ;
337- ilg . Emit ( OpCodes . Ldloc , format ) ;
338- ilg . Emit ( OpCodes . Box , typeof ( Format ) ) ;
339- ilg . Emit ( OpCodes . Call , Methods . Format_ToString ) ;
345+ loadPeekedFormatName ( ) ;
340346 ilg . Emit ( OpCodes . Ldstr , targetType . Name ) ;
341347 ilg . Emit ( OpCodes . Call , Methods . String_Format_String_Object_Object_Object ) ;
342348 throwException ( ) ;
0 commit comments