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 during json serialize of DynamicClass #640

Closed
BlueBasher opened this issue Oct 28, 2022 · 4 comments
Closed

NullReferenceException during json serialize of DynamicClass #640

BlueBasher opened this issue Oct 28, 2022 · 4 comments
Assignees
Labels

Comments

@BlueBasher
Copy link

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

DynamicClass throws exception when serializing to Json.

2. Exception

NullReferenceException

3. Fiddle or Project

using Newtonsoft.Json;
using System.Linq.Dynamic.Core;
using System.Text.Json.Serialization;

DynamicProperty[] props = new DynamicProperty[] { new DynamicProperty("Name", typeof(string)), new DynamicProperty("Birthday", typeof(DateTime)) };
Type type = DynamicClassFactory.CreateType(props);
DynamicClass dynamicClass = Activator.CreateInstance(type) as DynamicClass;
dynamicClass.SetDynamicPropertyValue("Name", "Albert");
dynamicClass.SetDynamicPropertyValue("Birthday", new DateTime(1879, 3, 14));
Console.WriteLine(dynamicClass);

JsonConvert.SerializeObject(dynamicClass);

Console.ReadLine();

4. Any further technical details

It seems the issue has been fixed in this commit.
This commit has been done a few minutes before creating release 1.2.20 but it is actually not part of that release.
Not sure if this was on purpose but it would be really nice if a new release could be made that includes the bugfix.

@StefH
Copy link
Collaborator

StefH commented Oct 28, 2022

The fix is indeed not yet present in the new version.
https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/CHANGELOG.md

I'll also add this example to the unit-test to be sure that it works correct.

@BlueBasher
Copy link
Author

Cool, thanks for the info! Do you have any indication when you expect version 1.2.21 to be released?

@StefH
Copy link
Collaborator

StefH commented Oct 28, 2022

I'll try to release a new version this weekend.

@StefH
Copy link
Collaborator

StefH commented Oct 28, 2022

#641

@StefH StefH self-assigned this Oct 28, 2022
@StefH StefH added the bug label Oct 28, 2022
@StefH StefH closed this as completed Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants