GithubHelp home page GithubHelp logo

polenter / sharpserializer Goto Github PK

View Code? Open in Web Editor NEW
110.0 2.0 28.0 322 KB

SharpSerializer can serialize types like: multidimensional array, nested array, array-of-arrays, polymorphic object (where value is inherited from the property type), generic type, generic listing (i.e. dictionary, collection) and many more, with a single line of code

Home Page: https://www.sharpserializer.net

License: Other

C# 100.00%

sharpserializer's Introduction

SharpSerializer 4.x

SharpSerializer is an open source XML and binary serializer for .NET. With only one line of code it can serialize types like: multidimensional array, nested array, array-of-arrays, polymorphic object (where value is inherited from the property type), generic type, generic listing (i.e. dictionary, collection) and many more...

Project URL: https://github.com/polenter/SharpSerializer

License URL: https://github.com/polenter/SharpSerializer/blob/master/LICENSE.txt

Prerequisites

Runtime

SharpSerializer requires .NET Framework 4.6.2 or a .NET platform implementing .NET Standard 2.0.

Below link contains a list with supported .NET implementations:
.NET Standard 2.0

Installation

From NuGet

Using NuGet is recommended.

In Visual Studio open NuGet Package Manager and type-in: Install-Package Polenter.SharpSerializer

In the Command Line (.NET CLI) use the dotnet command:

dotnet add package SharpSerializer

From a standalone file

The following libraries should be attached to your deployment package:

  • Polenter.SharpSerializer.dll

Usage

var obj = CreateMyVerySophisticatedObject();
var serializer = new SharpSerializer();
serializer.Serialize(obj, "test.xml");
var obj2 = serializer.Deserialize("test.xml");

There are more usage examples on the tutorial page:
http://sharpserializer.com/en/tutorial/

Usage Limitations

SharpSerializer serializes only public properties. If you like to serialize fields or private properties, they have to be wrapped in public properties.

SharpSerializer can deserialize only types providing public or private default constructor.

Please refer to the following article for a workaround:
https://www.codeproject.com/Articles/240621/How-to-serialize-data-effectively-Custom-serializa

Breaking Changes

3.x -> 4.x

Abandoned support for netstandard1.0, netstandard1.3, netcoreapp3.1 and net452.

Using .NET 8 in demo projects and in unit tests.

2.x -> 3.x

All platforms below .NET Framework 4.5 are no more supported.

Support for Portable Class Library (PCL) was depreciated. The following file is no more deployed:

  • Polenter.SharpSerializer.Portable.dll

There are no breaking changes in the API in .NET Framework 4.5.2 and above.

There are no breaking changes in the API expected, if using PCL, however it's not thoroughly tested yet.

The BSD License (BSD) was changed to MIT License

Deployment

NuGet

cd ./SharpSerializer
dotnet build -c Release
dotnet pack -c Release
dotnet nuget push .\bin\Release\SharpSerializer.4.0.2.nupkg -k <your-nuget-api-key>

Contributing

There are some tests concerning deploying and using SharpSerializer on different platforms, e.g. .NET Framework 4.5.2, .NET Core 1.0, 2.0 and Xamarin.
More tests on different platforms are however appreciated.

Additional contributors are welcome. Just change source code, create unit tests and request a pull.

Authors

Pawel Idzikowski, polenter (owner)

License

This project is licensed under the MIT License - see LICENSE.txt file for details.

Copyright notice

The following copyright notice should be attached to your software (e.g. about box):

This software includes SharpSerializer - Copyright (c) 2010 Pawel Idzikowski

sharpserializer's People

Contributors

1ol1 avatar econtideda avatar polenter avatar rmay-tws avatar strugglesharp avatar taylorjonl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sharpserializer's Issues

Ignore attributes/properties from deserialization

There are no settings to ignore attributes/properties from deserialization.

The settings:
SharpSerializerSettings.AdvancedSettings.AttributesToIgnore
SharpSerializerSettings.AdvancedSettings.PropertiesToIgnore
Are only used to ignore from serialization, not from deserialization.

It would be nice if there was a built in way to do this.

I found a workaround from an answer I got to a question I posted about this here:
SharpSerializer: Ignore attributes/properties from deserialization

Serializing a "circular dictionary" (a dictionary made circular with overridden indexer) results in index out of range exception.

1st things 1st, thank you for your work, it is amazing and easy to use! I encountered a problem, however:

I implemented a simple CircularDictionary for a university project of mine:
public class CircularDictionary<TValue> : Dictionary<int, TValue> { public new TValue this[int i] { get { return base[i % this.Count]; } set { base[i] = value; } } }
For some reason, SharpSerializer's serialization always results in an index out of range exception. When I copy/pasted my data from the ciruclar to a normal one, serialization worked perfectly. Strangely though, it has no problem with my likewise simple CircularList: (GetNextElement and WhatIsNext, as you can see, has no contribution to indexing)
` public class CircularList : ObservableCollection
{
int inc;
public CircularList()
{
inc = 0;
}

    public new T this[int i]
    {
        get
        {
            return base[i % this.Count];
        }
        set
        {
            base[i] = value;
        }
    }

    public T GetNextElement(int number = 1)
    {
        return this[inc+=number];
    }

    public T WhatIsNext()
    {
        return this[inc + 1];
    }
}`

NullReferenceException when serializing (using Version 3.0.1)

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)

Cannot serialize an array when using .NET Core, .NET 5 or later

Note: This issue seems to already be reported in previous issues but the exact case and cause where not provided.

Bug description

When using SharpSerializer NuGet package in a project targeting platforms .NET Core, .NET 5 or later, serializing an array will throw an error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'
When using the NuGet package in a .Net Framework project this did not happen.

Bug source

Before I go in to details, it is needed to mention that the SharpSerializer project targets the following platforms: ".NET Standard 1.0", ".NET Standard 1.3", ".NET Framework 4.5.2", so a .NET Core or .NET 5 project will use the .NET Standard version.

I downloaded the source code and ran the same code and got the same error. The error occurred in class ArrayAnalyzer ("master/SharpSerializer/Core/ArrayAnalyzer.cs"). Method getLength calls arrayType.GetMethod("GetLength"); to get the MthodInfo of the array Type needed for serialization. In .Net Framework and .Net Standard 2.0+ this simply calls the Type.GetMethod method. In .NET Standard lower than 2.0, this method does not exist. To overcome this, an extension method for Type was added in class TypeExtensions.cs ("master/SharpSerializer/Core/TypeExtensions.cs"). The extension method calls type.GetTypeInfo().GetDeclaredMethod(…) to get the MthodInfo. The problem is that declared methods are only methods declared by the current type, not by inherited types, so the MthodInfo returned is null.

Solution

The SharpSerializer project target platforms needs to be updated.
Option 1: update the project to target ".NET Standard 2.0" or higher and the extension method will not be required.
Option 2: update the project to target ".NET Standard 1.5" or higher and change the extension to call type.GetTypeInfo().GetMethod(…).

Upgrade from Framework 4.5 to .Net 6.0 deserializer exceptions

I am in the process of upgrading my application from .Net Framework 4.5 to .Net 6.0 and at the same time SharpSerializer 2.20.0 to 3.0.2.

I have a couple of different object models which are persisted by the previous version which I need the new version to deserialise and I'm running into a couple of issues (different exception for each object model):

  1. In this case I get two inner exceptions:

MissingMethodException: Constructor on type 'X.Y.Z.ApplicationSettings' not found.

AND

CreatingInstanceException: Error during creating an object. Please check if the type "SportGeek.Adjudicate.Support.ApplicationStateModel.ApplicationSettings, SportGeek.Adjudicate.Support, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" has a parameterless constructor, or if the settings IncludeAssemblyVersionInTypeName, IncludeCultureInTypeName, IncludePublicKeyTokenInTypeName are set to true. Details are in the inner exception.

  1. I'm getting:

{"Could not load type 'System.RuntimeType' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.":"System.RuntimeType"}

Issue 1 is clearly stating which class it thinks does not have a parameterless constructor but in fact ApplicationSettings certainly does have a parameterless constructor (if it didn't then it wouldn't work with the old version). There is the hint to check Include_Name settings: the xml I am trying to deserialise does include "Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" and the new version is now just "1.0.0" but I have tried changing that manually with a find an replace and it has made no difference.

I think Issue 2 may indicate I have some .Net type in the serialised object model that now can't be deserialised in .Net 6 but I hope I'm wrong about that as I'd be a bit stuck! The object models are rather complex so just trying to track down what type was the problem would be tricky.

File not fount Exception

SharpSerializer sharpSerializer = new SharpSerializer(true);
using (FileStream stream = new FileStream(@"E:\JetBrains Workspace\RiderProjects\ss_c\pro.bin",
         FileMode.Open, FileAccess.Read))
{
         var objs = sharpSerializer.Deserialize(stream);
}

The code is as above.
I reported an error when using it according to the official example:

Unhandled exception. Polenter.Serialization.Core.DeserializingException: An error occured during the deserialization. Details are in the inner exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Data, Culture=neutral, PublicKeyToken=null'. System could not find file.
File name: 'Data, Culture=neutral, PublicKeyToken=null'

But the file is exists.

DateTimeOffset serialization failure

When serializing/deserializing DateTimeOffset properties, the date is set to the default value of 1/1/0001 12:00:00 AM +00:00.
Conversely, DateTime properties work as expected.

LINQPad script: http://share.linqpad.net/i8covu.linq

void Main()
{
	var dtA = new DateTimeOffsetExample { Date = DateTimeOffset.Now };
	var dtB = new DateTimeExample { Date = DateTime.Now };

	var bytesA = ObjectToByteArray(dtA);
	ByteArrayToObject<DateTimeOffsetExample>(bytesA).Dump();

	var bytesB = ObjectToByteArray(dtB);
	ByteArrayToObject<DateTimeExample>(bytesB).Dump();
}

public class DateTimeExample
{
	public DateTime Date { get; set; }
}

public class DateTimeOffsetExample
{
	public DateTimeOffset Date { get; set; }
}

public static byte[] ObjectToByteArray(object obj)
{
	if (obj == null)
	{
		return Array.Empty<byte>();
	}

	using var ms = new MemoryStream();
	var serializer = new SharpSerializer(true);
	serializer.Serialize(obj, ms);

	return ms.ToArray();
}

public static T ByteArrayToObject<T>(byte[] arrBytes)
{
	if (arrBytes == null)
	{
		return default(T);
	}

	using var memStream = new MemoryStream();
	memStream.Write(arrBytes, 0, arrBytes.Length);
	memStream.Seek(0, SeekOrigin.Begin);
	var serializer = new SharpSerializer(true);
	var obj = serializer.Deserialize(memStream);

	return (T)obj;
}

Yields:
image

Serializing returns empty text and exception when serializing collections (and the solution)

Hi I've tried using the nuget, but there is some weird behavior with collections. So I downloaded the code, there I found two issues:

  1. Thereturn true in line 175 is redundant, causing all properties to be ignored. and results in an empty serialization data.


    Removing these lines solved this issue.

  2. My issue with collections and references. When deserialized a collection that includes a reference to an object that was already added I got an exception with the following message:
    Property type is not defined. Property: "" which is thrown here:

    if (property.Type == null)
    {
    // there is no property type and no expected type defined. Give up!
    throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"",
    property.Name));
    }

    The reason for the exception is that property.type is not defined because in the xml string (I guess the same happens also with the binary serializer) there is no type defined for this property, and there shouldn't be one - because it was already defined for the reference object.
    So my solution was to move the reference part:
    var referenceTarget = property as ReferenceTargetProperty;

    and
    if (referenceTarget.Reference != null)
    {
    if (!referenceTarget.Reference.IsProcessed)
    {
    // object was created already
    // get object from cache
    return _objectCache[referenceTarget.Reference.Id];
    }
    }

to before line 82 - this solved this issue.

So the new code looks like this:

            // Is it NullProperty?
            var nullProperty = property as NullProperty;
            if (nullProperty != null)
            {
                return null;
            }

            var referenceTarget = property as ReferenceTargetProperty;
            if (referenceTarget!=null && referenceTarget.Reference != null)
            {
                if (!referenceTarget.Reference.IsProcessed)
                {
                    // object was created already
                    // get object from cache
                    return _objectCache[referenceTarget.Reference.Id];
                }
            }

            if (property.Type == null)
            {
                // there is no property type and no expected type defined. Give up!
                throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"",
                                                                  property.Name));
            }

            // Is it SimpleProperty?
            var simpleProperty = property as SimpleProperty;
            if (simpleProperty != null)
            {
                return createObjectFromSimpleProperty(simpleProperty);
            }

            
            if (referenceTarget == null)
                return null;

            

            object value = createObjectCore(referenceTarget);
            if (value != null)
                return value;

I don't know how to upload these changes to the code, so I simply outlining this here.

Properties without setter are skipped

If I have only getter and not setter - property is not serialized into complex (to xml). I need to write set{} to fix it. Why we need to have setter?

DeserializingException, An item with the same key has already been added. Second time deserialization

Hi,

we had a strange issue in our tests when we added SharpSerializer serialization/deserialization (v 3.0.1) to our caching. The second time we deserialize a list, which contains the same element several times we get the exceptions.

    class Foo
    {
        public string ID { get; set; } = Guid.NewGuid().ToString();
    }

    [Fact]
    public async Task Serialization_DeSerializationFails__IfTheObjectsAreTheSame()
    {
        var data = Enumerable.Repeat(new Foo(), 2).ToList(); //same object, same reference
        var deSerializedOk = data.ToByteArray().FromByteArray<List<Foo>>();
        var deSerializedFails = data.ToByteArray().FromByteArray<List<Foo>>();
    }

The extension methods are like:

    private static readonly SharpSerializer Serializer = new SharpSerializer(new SharpSerializerBinarySettings()
    {
        Encoding = Encoding.Unicode
    });

    public static byte[] ToByteArray<tt>(this tt obj)
    {
        if (obj == null)
            return null;

        using (var ms = new MemoryStream())
        {
            Serializer.Serialize(obj, ms);
            return ms.ToArray();
        }
    }

    public static tt FromByteArray<tt>(this byte[] data)
    {
        if (data == null)
            return default(tt);

        using (MemoryStream ms = new MemoryStream(data,false))
        {
            var obj = Serializer.Deserialize(ms);
            if (obj is tt deserialized)
                return deserialized;
            return default(tt);
        }
    }

Exceptions stacktrace:

System.ArgumentException
An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType) at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readItems(ICollection1 items, Type expectedElementType)
at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.Deserialize()
at Polenter.Serialization.SharpSerializer.Deserialize(Stream stream)

Any help would really be appreciated!

When deserialize SharpSerializer throw "Constructor on type not found."

Hi, I'm new to SharpSerializer. When I try to write a demo, the serialize function is OK, but when I deserialize the serialize result, SharpSerializer throws an inmost ex "Constructor on type not found.". The code is like this:

public class MyClass
{
    public int Id { get; set; }
    public string? Name { get; set; }
}

public void Test()
{
        var myObject = new MyClass { Id = 1, Name = "Example" };

        var serializer = new Polenter.Serialization.SharpSerializer();
        var ms = new MemoryStream();
        serializer.Serialize(myObject,ms);
        ms.Seek(0, SeekOrigin.Begin);

        // this line throws the ex
       var deserializedObject = serializer.Deserialize (ms) as MyClass;
}

No parameterless constructor defined for this object.

When I try to deserialize a complex object I'm getting the following error:
No parameterless constructor defined for this object.

I obviously have a class somewhere without a parameterless constructor, the problem is I don't know which one. Can this please be updated to include the type that it is failing to create?
Call stack:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)

Objects with private properties can't share property names

This is kind of difficult to explain, but here is the code to reproduce:

public class TestMain
    {
        public string TestProperty
        {
            get
            {
                return "Test";
            }
        }
        private TestDetail TestDetails { get; set; } = new TestDetail();

    }
    public class TestDetail
    {
        public string TestProperty { get; set; } = "TestDetail";
        
    }

Called with the following:

TestMain tr = new TestMain();

SharpSerializer serializer = new SharpSerializer();
serializer.Serialize(tr, "test.bin");

SharpSerializer serializer2 = new SharpSerializer();
serializer2.Deserialize("test.bin");

This will throw the following exception when deserializing:
ArgumentException: Property set method not found.

If you rename the TestProperty on the TestMain class, or the TestDetail class then it will deserialize without issues.

Item of type FontFamily not correctly serialized.

Hi,

I tried to use your serializer on an object containing a property of type FontFamily. I got the following XML:

<Complex name="FontFamily">
  <Properties>
    <Simple name="Baseline" value="0.921630859375" />
    <Simple name="LineSpacing" value="1.14990234375" />
  </Properties>
</Complex>

Clearly some of its properties are not listed. Also:
I tried to make it ignore the property Transform,, but apparently that only works on properties of the serialized object, and not on sub properties.

Serialization between .Net4.8 and .NetCore

Hi
First of all, thank you sharing your fantastic code with the community. it saved me HOURS of developing an own solution!

I had some problems serializing between a .Net4.8 and .NetCore assembly. Because Microsoft changed the assembly of some basic .Net types like String, Guid, ...

I solved the problem by a little change on the TypeNameConverter. When setting the new Property UseSimpleNameForKnownDotNetTypes, the ConvertToTypeName() only uses the FullName of basic .Net types. The Type.GetType() on the other hand is able to resolve it (see code below).

Or do you have a better solution to this scenario?
Cheers, jaz (bluebat)

public sealed class TypeNameConverter : ITypeNameConverter
{
    // .NetCore changed the FQN of some basic types like String so .Net4.8 can not GetType() of System.String with FQN of .NetCore, but can handle when used with simple names.
    public bool UseSimpleNameForKnownDotNetTypes { get; private set; }
	
    ... some code inbetween ...
	
    public string ConvertToTypeName(Type type)
    {
        ... some code inbetween ...
        
        if (UseSimpleNameForKnownDotNetTypes && IsKnownDotNetBaseType(type))
            typename = type.FullName;
        
        ... some code inbetween ...
    }
	
    public static bool IsKnownDotNetBaseType(Type type)
    {
        // enums must be serialized into numbers
        if (type.IsEnum)
            return false;
	
        // Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, Single
        if (type.IsPrimitive)
            return true;
	
        // DBNull, Decimal, DateTime, String
        TypeCode typeCode = Type.GetTypeCode(type);
        bool hasKnownTypeCode = typeCode != TypeCode.Object && typeCode != TypeCode.Empty;
        if (hasKnownTypeCode)
            return true;
	
        return type == typeof(Guid) ||
               type == typeof(Version);
    }
}

Object reference not set to an instance of an object (XmlSerializer) - Version 3.0.1

I try to reproduce this exception, and found that the array is the problem. Here what cause the problem.

public class Program
{
    public static void Main()
    {
        Test t = new Test();
        t.ASD = new[] { "asdf", "afff" };

        SharpSerializer ss = new SharpSerializer();
        FileStream fs = new FileStream("D:\\KsdK.txt", FileMode.Create);
        ss.Serialize(t, fs);
    }

    public class Test
    {
        public string[] ASD { get; set; }
    }
}

The ss.Serialize(t, fs) throw NullReferenceException at Polenter.Serialization.Core.ArrayAnalyzer.getLength(Int32 dimension, Type arrayType)

Ignore Public Static Properties

Hi

There is a problem with TypeExtensions.GetPublicInstanceProperties(). it get's also all static and nonpublic properties.

A short blink into ILSpy I saw that GetRuntimeProperties() will call GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic). So GetPublicInstanceProperties() will also get static and nonpublic properties.

I changed the code to solve this problem:

  1. extended AdvancedSharpSerializerBinarySettings with two new properties
    public bool IncludeStaticProperties { get; set; }
    public bool IncludeNonPublicProperties { get; set; }

  2. extended the PropertyProvider with two new properties
    public bool IncludeStatic { get; set; }
    public bool IncludeNonPublic { get; set; }

  3. assigning the props in SharpSerializer.initialize()
    PropertyProvider.IncludeNonPublic = settings.AdvancedSettings.IncludeNonPublicProperties;
    PropertyProvider.IncludeStatic = settings.AdvancedSettings.IncludeStaticProperties;

  4. finally changed PropertyProvider.GetAllProperties()

protected virtual PropertyInfo[] GetAllProperties(Type type)
{
  var flags = BindingFlags.Instance | BindingFlags.Public;
  
  if (IncludeStatic)
    flags |= BindingFlags.Static;
  
  if (IncludeNonPublic)
    flags |= BindingFlags.NonPublic;
  
  return type.GetProperties(flags);
}

Hope, this helps someone with the same problem.
Cheers, jaz (bluebat)

ASP.NET

Can this serializer be used with ASP.NET?

AddXmlSerializerFormatters adds XML formatters based on XmlSerializer, but it can't handle serialisation of dictionaries, so I'm looking to use a more capable XML serializer instead.

Help debugging "Property set method not found."

I've done a major refactor of my application and am running into a "Property set method not found." error when I deserialize current files in my refactored apps. Is there any way to narrow down what property it is having problems with?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.