runtime: System.Text.Json does not support constructors with byref parameters.

Description

I have a List of objects whose constructors take ‘in’ parameters of DateTime and TimeSpan.

public class TestClass
    {
        public TestClass(in DateTime dateTime, in TimeSpan timeSpan)
        {
            DateTime = dateTime;
            TimeSpan = timeSpan;
        }

        public DateTime DateTime { get; set; }

        public TimeSpan TimeSpan { get; set; }
    }

When serializing a list of these objects, I am seeing the exception in the title being thrown:

image

image

This is specifically being thrown at IEnumerableDefaultConverter.cs line 255:

state.Current.DeclaredJsonPropertyInfo = state.Current.JsonClassInfo.ElementClassInfo!.PropertyInfoForClassInfo;

Unfortunately I have absolutely no clue what the issue is here. I’m hoping you might be able to help.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 25 (14 by maintainers)

Most upvoted comments

@ViktorHofer Im on 43b1ce5

Thanks for letting us know. Would it be possible for you to rebase onto the current main’s HEAD? I assume that some of the issues that you were seeing will go away by doing so. After rebasing make sure that you do a clean build:

git clean -xdf
./build.sh clr+libs -rc Release

@GrabYourPitchforks, @ilanb1996 sounds good, thanks! I’ll assign the issue to you - please tag me with any questions.