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

NullReferenceException when serializing (using Version 3.0.1) #6

Open
tobiasschittkowski opened this issue Jun 8, 2018 · 4 comments

Comments

@tobiasschittkowski
Copy link

I get the following NullReferenceException when trying to serialize to binary (Burst mode):

bei Polenter.Serialization.Advanced.BinaryPropertySerializer.writeProperties(PropertyCollection properties, Type ownerType)
bei Polenter.Serialization.Advanced.BinaryPropertySerializer.SerializeComplexProperty(PropertyTypeInfo1 property) bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.serializeReferenceTarget(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.SerializeCore(PropertyTypeInfo1 property) bei Polenter.Serialization.Advanced.BinaryPropertySerializer.writeProperties(PropertyCollection properties, Type ownerType) bei Polenter.Serialization.Advanced.BinaryPropertySerializer.SerializeComplexProperty(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.serializeReferenceTarget(PropertyTypeInfo1 property) bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.SerializeCore(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.BinaryPropertySerializer.writeItems(ICollection1 items, Type defaultItemType) bei Polenter.Serialization.Advanced.BinaryPropertySerializer.SerializeCollectionProperty(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.serializeReferenceTarget(PropertyTypeInfo1 property) bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.SerializeCore(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.BinaryPropertySerializer.writeProperties(PropertyCollection properties, Type ownerType)
bei Polenter.Serialization.Advanced.BinaryPropertySerializer.SerializeComplexProperty(PropertyTypeInfo1 property) bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.serializeReferenceTarget(PropertyTypeInfo1 property)
bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.SerializeCore(PropertyTypeInfo`1 property)
bei Polenter.Serialization.Advanced.Serializing.PropertySerializer.Serialize(Property property)
bei Polenter.Serialization.SharpSerializer.Serialize(Object data, Stream stream)

@gave92
Copy link

gave92 commented Aug 11, 2018

I get the same error. Using version 2.20.0 works fine.

@caioaletroca
Copy link

caioaletroca commented Dec 1, 2018

I'm getting the same error, no clue about whats is causing it. But I can't use 2.20 since I also need .NET 4.7
SharpSerializer really would save me :(

@rjpramos
Copy link

rjpramos commented Jan 16, 2020

In our case the problem was due to the fact that we had private getters and setters (probably bad copy-paste from someone :D).

This caused such properties to be included in the PropertyCollection:

private void writeProperties(PropertyCollection properties, Type ownerType)
{
	// How many
	_writer.WriteNumber(Convert.ToInt16(properties.Count));

	// Serialize all of them
	foreach (Property property in properties)
	{
		PropertyInfo propertyInfo = ownerType.GetProperty(property.Name);
		SerializeCore(new PropertyTypeInfo<Property>(property, propertyInfo.PropertyType));
	}
}

Then in the part ownerType.GetProperty(property.Name) you will just get a null because GetProperty() can't find it.

The null pointer exception comes from propertyInfo.PropertyType.

Removing the private getters and setters solved our problem (but still it would be nice to improve the code of SharpSerializer).

@Steph55
Copy link

Steph55 commented Jun 24, 2020

Actually, the exception might be caused by a bug that seems to be in SharpSerializer since a long time. It will fail if you try to serialize an array of simple types. For instance, try to serialize this one and you will get the bug:

   public class Test
    {
        public int[] f { get; set; }
        public Test()
        {
            f = new int[] { 1, 2, 3, 4, 5, 6, 7 };
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants