troubleshooting Question

Member 'names' cannot be initialized in an object initializer expression because it is shared

Avatar of Ruffone
Ruffone asked on
ASP.NETVisual Basic.NET
2 Comments1 Solution348 ViewsLast Modified:
How can I ininitialize the "names" property on the "TestPerson" class. The code below throws an error. "Member 'names' cannot be initialized in an object initializer expression because it is shared"

 Return From p In Me.peopleRep.GetAll()
               Let names = Me.nameSvc.GetAll(p.personGuid)
               Select New Credit.Person _
               With {.personId = p.personId,
                     .birthDay = p.birthDay,
                     .gender = p.gender,
                     .names = New ObservableCollection(Of Credit.Name)(names)
                    }

Public Class TestPerson
    Public Property birthDay As String
    Public Property gender As String
    Public Shared Property names As ICollection(Of Name)
        Get
            Return _names
        End Get
        Set(value As ICollection(Of Name))
            _names = value
        End Set
    End Property
    Private Shared _names As ObservableCollection(Of Name) = Nothing
End Class
ASKER CERTIFIED SOLUTION
Corey Scheich
Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros