0

I am getting error like Object reference not set to an instance of an object.

But while debugging I see value is coming perfectly in variable, so any idea why still this error is coming.

please see below image and below code also.

var vipAppointmentType = await _codeTypeRepository.GetCodeSetsAsQueryable()
                    .FirstOrDefaultAsync(c => c.Id == entity.VIPTypeId);

var dto = ViewVipAppointmentTypeDto.Create(
          entity.Id,
          entity.Code,
          entity.Description,
          vipAppointmentType.Name,
          entity.IsFreeMembership);

dto.VipType.Id = vipAppointmentType.Id;
dto.VipType.Name = vipAppointmentType.Name;
dto.VipType.AbbreviationCode = vipAppointmentType.AbbreviationCode;
Nic
  • 439
  • 4
  • 14

1 Answers1

3

Your dto.VipType is null. Initialize VipType as follows:

dto.VipType=new VipType(); // add this line
dto.VipType.Id = vipAppointmentType.Id;
dto.VipType.Name = vipAppointmentType.Name;
dto.VipType.AbbreviationCode = vipAppointmentType.AbbreviationCode;
Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34