Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default(ImmutableArray<T>) to be serialized #5587

Merged
merged 1 commit into from
May 8, 2019
Merged

Allow default(ImmutableArray<T>) to be serialized #5587

merged 1 commit into from
May 8, 2019

Conversation

Liversage
Copy link
Contributor

ImmutableArray<T> is a value type and the default value will throw NullReferenceException when the Length property is read. The serializer will read this property to determine how many elements in the array should be written to the stream making it impossible to serialize default(ImmutableArray<T>).

This change ensures that default(ImmutableArray<T>) can be serialized without throwing a NullReferenceException. The value default(ImmutableArray<T>) is indicated by writing -1 as the length of the array to the stream. Note that ImmutableArray<T>.Empty has a length of 0 so the code is able to distinguish between the two values.

The deserializer will make a call to context.RecordObject. I do not quite understand the purpose of this call and if it is meaningful to do with a value type but I included it in the added code because it was already in the existing code.

I have added a test that verifies that default(ImmutableArray<T>) can round-trip when serialized.

@dnfclas
Copy link

dnfclas commented May 8, 2019

CLA assistant check
All CLA requirements met.

@Liversage
Copy link
Contributor Author

The functional check had a failed test:

UnitTests.ActivationsLifeCycleTests.ActivationCollectorTests.ActivationCollectorShouldNotCollectBusyActivationsSpecifiedInPerTypeConfiguration

with the following exception message:

System.Net.Sockets.SocketException : An attempt was made to access a socket in a way forbidden by its access permissions

It seems unlikely to me that my change caused a regression in this test but any advice on how to resolve it will be appreciated.

@ReubenBond
Copy link
Member

@Liversage that exception message is prevalent on those old Jenkins machines - I think something kills the job/sockets sometimes. Nothing to worry about.

@ReubenBond ReubenBond merged commit 94c5cab into dotnet:master May 8, 2019
@ReubenBond
Copy link
Member

Thank you, @Liversage!

sergeybykov pushed a commit to sergeybykov/orleans that referenced this pull request May 31, 2019
ReubenBond pushed a commit that referenced this pull request May 31, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants