@@ -268,10 +268,20 @@ public static Func<Unpacker, DasherContext, object> Build(Type type, UnexpectedF
268
268
// If we got here then the property was not recognised. Either throw or ignore, depending upon configuration.
269
269
if ( unexpectedFieldBehaviour == UnexpectedFieldBehaviour . Throw )
270
270
{
271
- ilg . Emit ( OpCodes . Ldstr , "Encountered unexpected field \" {0}\" for type \" {1}\" ." ) ;
271
+ var format = ilg . DeclareLocal ( typeof ( Format ) ) ;
272
+ ilg . Emit ( OpCodes . Ldloc , unpacker ) ;
273
+ ilg . Emit ( OpCodes . Ldloca , format ) ;
274
+ ilg . Emit ( OpCodes . Call , typeof ( Unpacker ) . GetMethod ( nameof ( Unpacker . TryPeekFormat ) ) ) ;
275
+ // Drop the return value: if false, 'format' will be 'Unknown' which is fine.
276
+ ilg . Emit ( OpCodes . Pop ) ;
277
+
278
+ ilg . Emit ( OpCodes . Ldstr , "Encountered unexpected field \" {0}\" of MsgPack format \" {1}\" for CLR type \" {2}\" ." ) ;
272
279
ilg . Emit ( OpCodes . Ldloc , key ) ;
280
+ ilg . Emit ( OpCodes . Ldloc , format ) ;
281
+ ilg . Emit ( OpCodes . Box , typeof ( Format ) ) ;
282
+ ilg . Emit ( OpCodes . Call , typeof ( Format ) . GetMethod ( nameof ( Format . ToString ) , new Type [ 0 ] ) ) ;
273
283
ilg . Emit ( OpCodes . Ldstr , type . Name ) ;
274
- ilg . Emit ( OpCodes . Call , typeof ( string ) . GetMethod ( nameof ( string . Format ) , new [ ] { typeof ( string ) , typeof ( object ) , typeof ( object ) } ) ) ;
284
+ ilg . Emit ( OpCodes . Call , typeof ( string ) . GetMethod ( nameof ( string . Format ) , new [ ] { typeof ( string ) , typeof ( object ) , typeof ( object ) , typeof ( object ) } ) ) ;
275
285
throwException ( ) ;
276
286
}
277
287
else
0 commit comments