• massoud-1045248 (1/29/2015)


    Hi everyone, not sure if anyone is still looking at this thread but recently I have been running into the following error. I inspected the data but I am not noticing anything unusual.

    Any input would be greatly appreciated.

    Thanks

    Msg 6522, Level 16, State 2, Line 2

    A .NET Framework error occurred during execution of user-defined routine or aggregate "Agg_Median":

    System.InvalidOperationException: Failed to compare two elements in the array. ---> System.ArgumentException: At least one object must implement IComparable.

    System.ArgumentException:

    at System.Collections.Comparer.Compare(Object a, Object b)

    at System.Array.SorterObjectArray.SwapIfGreaterWithItems(Int32 a, Int32 b)

    System.InvalidOperationException:

    at System.Array.SorterObjectArray.SwapIfGreaterWithItems(Int32 a, Int32 b)

    at System.Array.SorterObjectArray.QuickSort(Int32 left, Int32 right)

    at System.Array.Sort(Array keys, Array items, Int32 index, Int32 length, IComparer comparer)

    at System.Collections.ArrayList.Sort(Int32 index, Int32 count, IComparer comparer)

    at System.Collections.ArrayList.Sort()

    at Agg_Median.Write(BinaryWriter ToBeSerialized)

    Hello Massoud. Are you using the code from the article exactly as it is shown or did you make any modifications? I have no idea how it could be possible to get the error you posted above, nor the error you mentioned in the prior post (sorry, I never got a notification for that posting). Do you always or only sometimes get this error? The only problem I see, looking over the code again, is that it doesn't handle groups that have only NULL values, but that causes a different error: "Index was out of range". What version of SQL Server are you using? Can you post some sample data? How did you get past the error from last time regarding "Specified cast is not valid"?

    Take care,

    Solomon..

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR