Skip to content

Commit 39494fb

Browse files
Fix System.Version deserialization
System.Version was not deserializing if the Build or Revision components were not provided in the constructor.
1 parent aec94cb commit 39494fb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/MsgPack/Serialization/DefaultSerializers/System_VersionMessagePackSerializer.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ protected internal override Version UnpackFromCore( Unpacker unpacker )
7878
SerializationExceptions.ThrowMissingItem( 3, unpacker );
7979
}
8080

81+
if (build < 0 && revision < 0)
82+
{
83+
return new Version(major, minor);
84+
}
85+
else if (revision < 0)
86+
{
87+
return new Version(major, minor, build);
88+
}
89+
8190
return new Version( major, minor, build, revision );
8291
}
8392

@@ -129,6 +138,15 @@ protected internal override async Task<Version> UnpackFromAsyncCore( Unpacker un
129138
SerializationExceptions.ThrowMissingItem( 3, unpacker );
130139
}
131140

141+
if (build.Value < 0 && revision.Value < 0)
142+
{
143+
return new Version(major.Value, minor.Value);
144+
}
145+
else if (revision.Value < 0)
146+
{
147+
return new Version(major.Value, minor.Value, build.Value);
148+
}
149+
132150
return new Version( major.Value, minor.Value, build.Value, revision.Value );
133151
}
134152

0 commit comments

Comments
 (0)