Skip to content

Commit 38cd6df

Browse files
authored
CSHARP-5404: InvalidOperationException due to null casting in ConnectionId.ServerValue (#1538)
1 parent 024ecf0 commit 38cd6df

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/MongoDB.Driver/Core/Connections/ConnectionId.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public long LongLocalValue
106106
[Obsolete("Use LongServerValue instead.")]
107107
public int? ServerValue
108108
{
109-
get { return (int)_serverValue; }
109+
get { return (int?)_serverValue; }
110110
}
111111

112112
/// <summary>

tests/MongoDB.Driver.Tests/Core/Connections/ConnectionIdTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public void LongLocalValue_should_be_what_was_specified_in_the_constructor(long
9292
subject.LongLocalValue.Should().Be(localValue);
9393
}
9494

95+
[Fact]
96+
public void ServerValue_should_return_null_when_null()
97+
{
98+
var subject = new ConnectionId(__serverId, 10);
99+
100+
#pragma warning disable CS0618 // Type or member is obsolete
101+
subject.ServerValue.ShouldBeEquivalentTo(null);
102+
#pragma warning restore CS0618 // Type or member is obsolete
103+
}
104+
95105
[Theory]
96106
[InlineData(0)]
97107
[InlineData(int.MaxValue)]

0 commit comments

Comments
 (0)