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

IndexOutBoundException when packing scalar value with ByteArrayPacker #252

Closed
theolivenbaum opened this issue Aug 25, 2017 · 9 comments
Closed
Labels
bug Detected as bug

Comments

@theolivenbaum
Copy link

I'm getting the following exception when trying to serialize an object containing a Dictionary<int,int>, using PackSingleObjectAsync(object):

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MsgPack.MessagePackByteArrayPacker.WriteBytes(Byte header, UInt32 value)
at MsgPack.MessagePackByteArrayPacker.d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MsgPack.Serialization.DefaultSerializers.System_Int32MessagePackSerializer.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MsgPack.Serialization.MessagePackSerializer1.<PackToAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MsgPack.PackerUnpackerExtensions.<PackDictionaryAsyncCore>d__392.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MsgPack.Serialization.MessagePackSerializer1.<PackToAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MsgPack.Serialization.PackHelpers.<PackToArrayAsyncCore>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MsgPack.Serialization.MessagePackSerializer1.<PackToAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MsgPack.Serialization.MessagePackSerializer1.d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MsgPack.Serialization.MessagePackSerializer`1.d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

@BuairtRi
Copy link

I'm getting a similar error, but with a different StackTrack:

Index was outside the bounds of the array.
at MsgPack.MessagePackByteArrayPacker.WriteBytes(Byte header, UInt16 value)
at MsgPack.MessagePackByteArrayPacker.PackCore(Int16 value)
at MsgPack.Serialization.DefaultSerializers.DateTimeOffsetMessagePackSerializer.PackToCore(Packer packer, DateTimeOffset objectTree)
at MsgPack.Serialization.MessagePackSerializer1.PackTo(Packer packer, T objectTree) at MsgPack.Serialization.EmittingSerializers.Generated.Row52_Data_Models_Data_VehicleDetailSerializer1.PackValueOfDateAdded(Packer , VehicleDetail ) at MsgPack.Serialization.PackHelpers.PackToArray[TObject](PackToArrayParameters1& parameter)
at MsgPack.Serialization.EmittingSerializers.Generated.Row52_Data_Models_Data_VehicleDetailSerializer1.PackToCore(Packer , VehicleDetail )
at MsgPack.Serialization.MessagePackSerializer1.PackTo(Packer packer, T objectTree) at MsgPack.PackerUnpackerExtensions.PackCollectionCore[T](Packer source, IEnumerable1 collection, MessagePackSerializer1 itemSerializer) at MsgPack.Serialization.DefaultSerializers.System_Collections_Generic_List_1MessagePackSerializer1.PackToCore(Packer packer, List1 objectTree) at MsgPack.Serialization.MessagePackSerializer1.PackTo(Packer packer, T objectTree)
at MsgPack.Serialization.MessagePackSerializer1.PackSingleObjectAsBytes(T objectTree) at MsgPack.Serialization.MessagePackSerializer1.PackSingleObject(T objectTree)
at MsgPack.Serialization.MessagePackSerializer`1.InternalPackSingleObject(Object objectTree)
at MsgPack.Serialization.MessagePackSerializer.PackSingleObject(Object objectTree)

@BuairtRi
Copy link

Rolling back to Nuget 0.8.1 resolved the problem for me, so it looks like a bug with the latest release.

@yfakariya
Copy link
Member

Thank you for reporting! I will investigate it soon.

@yfakariya
Copy link
Member

@rafael-aero @BuairtRi
I failed to reproduce this issue. Could you tell me repro code? It should be caused by specific class layout to serialize.

@BuairtRi
Copy link

I'm trying to serialize a large .NET List of a simple POCO object:

`[DataContract]
[Serializable]
[ExportToTypescript]
public class VehicleDetail
{
[DataMember]
public long Id { get; set; }

    [DataMember]
    public string VIN { get; set; }

    [DataMember]
    public int Year { get; set; }

    [DataMember]
    public int? ModelId { get; set; }

    [DataMember]
    public string Model { get; set; }

    [DataMember]
    public int? MakeId { get; set; }

    [DataMember]
    public string Make { get; set; }

    [DataMember]
    public long LocationId { get; set; }

    [DataMember]
    public string LocationName { get; set; }

    [DataMember]
    public string City { get; set; }

    [DataMember]
    public string State { get; set; }

    [DataMember]
    public string Zip { get; set; }

    [DataMember]
    public string Row { get; set; }

    [DataMember]
    public DateTimeOffset DateAdded { get; set; }

    [DataMember]
    public string BarCodeNumber { get; set; }

    [DataMember]
    public bool HasImage { get; set; }

    [DataMember]
    public string Engine { get; set; }

    [DataMember]
    public string Transmission { get; set; }

    [DataMember]
    public string Trim { get; set; }

    [DataMember]
    public string AccountName { get; set; }

    [DataMember]
    public string Color { get; set; }

    [DataMember]
    public bool IsActive { get; set; }

    [DataMember]
    public bool AllowPullers { get; set; }

    [DataMember]
    public string Url { get; set; }
    [DataMember]
    public Guid? Size1 { get; set; }
    [DataMember]
    public Guid? Size2 { get; set; }
    [DataMember]
    public Guid? Size3 { get; set; }
    [DataMember]
    public Guid? Size4 { get; set; }
    [DataMember]
    public string Extension { get; set; }

    [DataMember]
    public string LocationImageName { get; set; }

    [DataMember]
    public string LocationImageLocation
    {
        get
        {
            if (LocationImageName != null && LocationImageName.Contains("://"))
                return LocationImageName;

            return "https://cdn.row52.com/cdn/images/accounts/" + LocationImageName;
        }
    }

    [DataMember]
    public string ImageName
    {
        get
        {
            return Size1 == default(Guid)
                       ? "https://cdn.row52.com/cdn/images/imagecomingsoon_600.jpg"
                       : Url + Size1.ToString().ToLower() + Extension;
        }
    }

    [DataMember]
    public string SmallImage
    {
        get
        {
            return Size3 == default(Guid)
                       ? "http://placehold.it/150x113"
                       : Url + Size3.ToString().ToLower() + Extension;
        }
    }

    [DataMember]
    public string LargeImage
    {
        get
        {
            return Size2 == default(Guid)
                       ? "http://placehold.it/150x113"
                       : Url + Size2.ToString().ToLower() + Extension;
        }
    }

    [DataMember]
    public string ThumbNail
    {
        get
        {
            return Size4 == default(Guid)
                       ? "https://cdn.row52.com/cdn/images/imagecomingsoon_150.png"
                       : Url + Size4.ToString().ToLower() + Extension;
        }
    }

    [DataMember]
    public DateTimeOffset ImageDate { get; set; }

    [DataMember]
    public DateTimeOffset? MostRecentComment { get; set; }

    [DataMember]
    public int ImageCount { get; set; }

    [DataMember]
    public string LocationCode { get; set; }

    [DataMember]
    public int CommentCount { get; set; }

    [DataMember]
    public Guid AccountId { get; set; }

    [DataMember]
    public DateTimeOffset CreationDate { get; set; }

    [DataMember]
    public long? FavoriteId { get; set; }

    [DataMember]
    public DateTimeOffset? FavoritedDate { get; set; }

    [DataMember]
    public int PullerCount { get; set; }

    [DataMember]
    public int PartsPullersCount { get; set; }

    [DataMember]
    public int PartsPullersForInYardsCount { get; set; }
}`

@yfakariya
Copy link
Member

@BuairtRi Thank you!

@yfakariya
Copy link
Member

I found a workaround. You should avoid this issue use Pack instead of PackSingleObject.

@yfakariya yfakariya added the bug Detected as bug label Aug 30, 2017
yfakariya added a commit that referenced this issue Aug 30, 2017
…emaining bytes is equal to packed scalar size. #252
@yfakariya yfakariya changed the title Issue serializing Dictionary<int,int> IndexOutBoundException when packing scalar value with ByteArrayPacker Aug 30, 2017
yfakariya added a commit that referenced this issue Aug 30, 2017
…emaining bytes is equal to packed scalar size. #252
yfakariya added a commit that referenced this issue Aug 30, 2017
I confirmed branch CI log shows "build succeeded" but never ends...
@yfakariya
Copy link
Member

I've fixed this issue and released 0.9.1 now. Please try it.

@BuairtRi
Copy link

Thanks! I'll reinstall the update soon and deploy to see if it's all working.

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

No branches or pull requests

3 participants