1

I don't know what is calling my Equals method, because when the breakpoint is hit there is no call stack (except the Equals itself and [External Code]).

I have a class UserComplete that has methods GetAll and Equals and some others including a constructor that accepts an array of objects. UserComplete Inherits from User. User class includes methods GetRows and Equals.

Equals is nothing special:

Public Overrides Function Equals(obj As Object) As Boolean
    If Not MyBase.Equals(obj) Then
        Return False
    End If
    Dim u As UserComplete = CType(obj, UserComplete)
    Return Me.RoleIds.Equals(u.RoleIds)
End Function

And GetAll just converts the object()() from the database or cache to a list of UserComplete

Public Function GetAll() As IList(Of UserComplete)
    Dim rows As Object()() = GetRows()
    If IsNothing(rows) Then
        Return Nothing
    End If

    Dim completeUsers As List(Of UserComplete) = (From u In rows Select New UserComplete(DirectCast(u, Object()))).ToList()
    If IsNothing(completeUsers) OrElse Not completeUsers.Any() Then
        Return Nothing
    End If
    Return completeUsers
End Function

I call GetAll from a service controller and actually get a response, no problem. Then after that is complete a breakpoint in Equals is hit, and obj is a List(Of Integers) with one value.

If you would expect this behavior, why? If not, can you explain why it might be occuring and how to fix it?

1 Answer 1

0

Ok, I have some information that may count as an answer. However, if someone can explain the "why" of the situation for the community I'll mark that as the answer.

I undid some Parallelism I had to help debug this temporarily (or permanently depending on if I decide this list is going to scale much). I found that the Equals method falls in the call stack under this

Sessions(u.Key) = DateTime.Now

where Sessions is a Dictionary(Of User, DateTime).

So, the simple answer is that when assigning a value to a Dictionary item System.Collections.Generic library calls Equals on each key in the Dictionary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.