-1

The following is the code :

            Dim x As New Google.Apis.Calendar.v3.Data.EventAttendee
            x.Email = "xxccxxxxx@gmail.com"
            x.DisplayName = "xxxxx"
            x.ResponseStatus = "Aproveed"
            Dim y As New Google.Apis.Calendar.v3.Data.EventAttendee
            y.Email = "xxxxxxx@gmail.com"
            y.DisplayName = "suji"
            y.ResponseStatus = "Aproveed"
            Dim attndList As New List(Of EventAttendee)
            attndList.Add(x)
            attndList.Add(y)
            Dim googleCalendarEvent As New [Event]()
            googleCalendarEvent.Attendees.Add(y)'<--- throws exception here
            googleCalendarEvent.Attendees.Add(x)

Exception details: Object reference not set to an instance of an object. why this is happening? how can i overcome this?

Updates when i use like:

 Dim googleCalendarEvent As New [Event]()
  googleCalendarEvent.Attendees = New EventAttendee()

it shows the error as

Unable to cast object of type 'Google.Apis.Calendar.v3.Data.EventAttendee' to type 'System.Collections.Generic.IList`1[Google.Apis.Calendar.v3.Data.EventAttendee]'.

vb.net
  • 31
  • 8
  • @ Bjørn-Roger Kringsjå : is it your job? check whether that link you provided answer for my question? – vb.net Dec 27 '14 at 09:56
  • Yes. And the duplicate is correct. The property `Attendees` is not instantiated. You need to create a new instance. `googleCalendarEvent.Attendees = New List(Of EventAttendee)` – Bjørn-Roger Kringsjå Dec 27 '14 at 09:59

1 Answers1

1
 Dim x As New Google.Apis.Calendar.v3.Data.EventAttendee
            x.Email = "xxccxxxxx@gmail.com"
            x.DisplayName = "xxxxx"
            x.ResponseStatus = "Aproveed"
            Dim y As New Google.Apis.Calendar.v3.Data.EventAttendee
            y.Email = "xxxxxxx@gmail.com"
            y.DisplayName = "suji"
            y.ResponseStatus = "Aproveed"
            Dim attndList As New List(Of EventAttendee)
            attndList.Add(x)
            attndList.Add(y)
            Dim googleCalendarEvent As New [Event]()
            googleCalendarEvent.Attendees = attndList

if you want to assign new list then do following thing.

    Dim googleCalendarEvent As New Google.Apis.Calendar.v3.Data.[Event]()
    googleCalendarEvent.Attendees = New List(Of EventAttendee)
    googleCalendarEvent.Attendees.Add(y)
    googleCalendarEvent.Attendees.Add(x)
dotnetstep
  • 17,065
  • 5
  • 54
  • 72
  • it will thrown error as : `Unable to cast object of type 'Google.Apis.Calendar.v3.Data.EventAttendee' to type 'System.Collections.Generic.IList`1[Google.Apis.Calendar.v3.Data.EventAttendee]'.` – vb.net Dec 27 '14 at 07:24