none
DataContractSerializer EnsureSetAsIsReference RRS feed

  • Question

  • Hi all!


    This question is related to this question[1] since we were not able to solve it properly. The problem described in there, of course, reoccured now.

    We spent more time investigating it and we are at the point now were we would like to know more about the following lines of code in the object reference stack[2]:

    if ((objectArray != null) && objectArray[count - 1] == obj)
    {
       if (isReferenceArray == null)
       {
         isReferenceArray = new bool[InitialArraySize];
       }
       else if (count == isReferenceArray.Length)
       {
         Array.Resize<bool>(ref isReferenceArray, isReferenceArray.Length * 2);
       }
       isReferenceArray[count - 1] = true;
    }

    Our application fails exactly at the else if (count == isReferenceArray.Length) comparrison, because we have the case: count == isReferenceArray.Length+1. Because of this the array does not get resized and we fail at isReferenceArray[count - 1] = true with an index out of bounce exception. Our question is:

    What is the reason you dont check for count >= isReferenceArray.Length to resize the array?

    Once again, we are sure that all our classes are properly defined (every class has IsReference=true). We could provoke this behaviour again by just adding some strings to the class project.


    Thank you in advance for your support!

    Best regards,

    Sam


    [1] https: //social.msdn.microsoft.com/Forums/vstudio/en-US/df00e45e-44c6-44d8-8e6c-68ecfa46e39f/datacontractserializer-stops-working?forum=wcf

    [2] http:// referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/ObjectReferenceStack.cs,00526dec84163041

    Monday, October 23, 2017 6:58 AM

Answers

  • Hello Edward,

    again, thank you for your help! We have reported this to Microsoft and indeed it is a bug. A fix is already in work.

    Greets,

    Sam

    • Marked as answer by Qerildan Wednesday, November 8, 2017 2:20 PM
    Wednesday, November 8, 2017 2:20 PM

All replies

  • Hi Qerildan,

    Could you share us your reproduceable project through OneDrive?

    After checking EnsureSetAsIsReference, it will resize isReferenceArray while count == isReferenceArray.Length, I am not sure how your count will be larger than isReferenceArray.Length.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 24, 2017 2:20 AM
  • Hi Edward,

    thank you for your response.

    > Could you share us your reproduceable project through OneDrive?

    I'm not sure that this is possible. Maybe we can find another solution? Like using Skype or smth? If that is not possible, we could try to somehow create a smaller project and try to reproduce it there, but this is potentially a big amount of work, since we are not sure how to reproduce it.

    We are also not sure why count is geting greater. It happens at very strange points, after changing some connecting between two classes, or after adding an attribute to one class. Do you have any documentation why it is checked for equality and not for greater or equal. Actually the problem is happening because EnsureSetAsIsReference is not called when count == isReferenceArray.Length, but right after that in the next iteration, but then Count is already greater.

    Greets,

    Sam

    Tuesday, October 24, 2017 5:42 AM
  • Hi Sam,

    This site is forum support, I am afraid we could not provide any further suggestion based on your current information. We only know your current wrong result, but, we did not know how this issue happened.

    Due to the limitation of forum support, I would suggest you consider Microsoft professional support, so that our engineers can work closely with you to troubleshoot this issue.

    If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 25, 2017 2:07 AM
  • Hello Edward,

    thank you for your response and all your work! We just tried to override all equals methods in our classes with a very simple one - just to make sure that this is not the cause of our pain. Sadly, we still face the same issue.

    As suggested we will get in touch with microsoft support, if you like, I will keep this question open and post the solution.

    Thanks again, greets

    Sam

    Wednesday, October 25, 2017 5:48 AM
  • One more thing, maybe you already have seen this in that context:

    We debugged closely through the code and came to the following situation:

    Our object to serialize is a list of items. This object gets placed on the object array, which gets resized from 4 to 8. Then the function OnHandleIsReference is called, but since a list is not is part of the contract, the if for !contract.IsReference holds, and the function returns, instead of calling EnsureSetAsIsReference. Because of not calling EnsureSetAsIsReference the reference array gets not resized from size 4 to 8 which results in the state: objectarray size: 8, reference array size: 4.

    Then of course for the next object we have the index out of bounce exception, since it wants to place an object at isReferenceArray[4].

    Again, thank you!

    Greets, Sam

    Wednesday, October 25, 2017 9:15 AM
  • Hi Sam,

    If you have any update about your issue, please feel free to let us know.

    I hope your issue will be resolved soon.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 26, 2017 1:26 AM
  • Hello Edward,

    again, thank you for your help! We have reported this to Microsoft and indeed it is a bug. A fix is already in work.

    Greets,

    Sam

    • Marked as answer by Qerildan Wednesday, November 8, 2017 2:20 PM
    Wednesday, November 8, 2017 2:20 PM