Skip to content

Commit 4caaff0

Browse files
committed
Fix intentionally "empty" member causes ANE in serializer generation. Issue #145
1 parent 6e14337 commit 4caaff0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/MsgPack/Serialization/SerializerGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ private static IEnumerable<Type> ExtractElementTypes( SerializationContext conte
486486
foreach (
487487
var dependentType in
488488
SerializationTarget.Prepare( context, type )
489-
.Members.SelectMany( m => ExtractElementTypes( context, configuration, m.Member.GetMemberValueType() ) )
489+
.Members.Where( m => m.Member != null ).SelectMany( m => ExtractElementTypes( context, configuration, m.Member.GetMemberValueType() ) )
490490
)
491491
{
492492
yield return dependentType;

test/MsgPack.UnitTest/Serialization/RegressionTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void Issue143()
266266
new int[] { 9, 8 },
267267
909
268268
};
269-
var serializer = MessagePackSerializer.Get<object>();
269+
var serializer = MessagePackSerializer.Get<object>( new SerializationContext() );
270270
var packedBinary = serializer.PackSingleObject( array );
271271
var unpacked = serializer.UnpackSingleObject( packedBinary );
272272
var unpackedList = ( ( MessagePackObject )unpacked ).AsList();
@@ -279,5 +279,38 @@ public void Issue143()
279279
Assert.That( unpackedList[ 2 ].AsList()[ 1 ] == 8 );
280280
Assert.That( unpackedList[ 3 ] == 909 );
281281
}
282+
283+
#if !NETFX_CORE && !WINDOWS_PHONE && !XAMIOS && !XAMDROID && !UNITY
284+
[Test]
285+
public void Issue145()
286+
{
287+
var results =
288+
SerializerGenerator.GenerateSerializerSourceCodes(
289+
new SerializerCodeGenerationConfiguration
290+
{
291+
EnumSerializationMethod = EnumSerializationMethod.ByUnderlyingValue,
292+
IsRecursive = true,
293+
OutputDirectory = Path.GetTempPath(),
294+
WithNullableSerializers = false,
295+
PreferReflectionBasedSerializer = true,
296+
SerializationMethod = SerializationMethod.Array
297+
},
298+
typeof( Issue145Class )
299+
).ToArray();
300+
foreach ( var result in results )
301+
{
302+
File.Delete( result.FilePath );
303+
}
304+
}
305+
306+
[DataContract]
307+
public class Issue145Class
308+
{
309+
[DataMember( Order = 0 )]
310+
public int MyProperty1 { get; set; }
311+
[DataMember( Order = 2 )]
312+
public int MyProperty2 { get; set; }
313+
}
314+
#endif // !NETFX_CORE && !WINDOWS_PHONE && !XAMIOS && !XAMDROID && !UNITY
282315
}
283316
}

0 commit comments

Comments
 (0)