✅ System.NullReferenceException: 'Object reference not set to an instance of an object.'
I get error when I map one object to other. I checked
sdc
object using debug and all properties aren't null. What can I do to solve the problem?
private Data.Entities.Station MapStationFeatureToStation(StationDetailsContract sdc)
{
return new Data.Entities.Station
{
Id = sdc.Id.ToString(),
TmsNumber = sdc.Properties.TmsNumber,
Name = sdc.Properties.Name,
Names =
{
Fi = sdc.Properties.Names?.Fi ?? string.Empty,
Sv = sdc.Properties.Names?.Sv ?? sdc.Properties.Names?.Fi ?? string.Empty,
En = sdc.Properties.Names?.En ?? sdc.Properties.Names?.Fi ?? string.Empty
},
Coordinates =
{
Longitude = sdc.Geometry.Coordinates[0],
Latitude = sdc.Geometry.Coordinates[1]
},
RoadNumber = sdc.Properties.RoadAddress.RoadNumber,
RoadSection = sdc.Properties.RoadAddress.RoadSection,
Carriageway = sdc.Properties.RoadAddress.Carriageway,
Side = sdc.Properties.RoadAddress.Side,
Municipality = sdc.Properties.Municipality,
MunicipalityCode = sdc.Properties.MunicipalityCode,
Province = sdc.Properties.Province,
ProvinceCode = sdc.Properties.ProvinceCode,
Direction1Municipality = sdc.Properties.Direction1Municipality,
Direction1MunicipalityCode = sdc.Properties.Direction1MunicipalityCode,
Direction2Municipality = sdc.Properties.Direction2Municipality,
Direction2MunicipalityCode = sdc.Properties.Direction2MunicipalityCode,
FreeFlowSpeed1 = sdc.Properties.FreeFlowSpeed1,
FreeFlowSpeed2 = sdc.Properties.FreeFlowSpeed2,
DataUpdatedTime = sdc.Properties.DataUpdatedTime
};
}
private Data.Entities.Station MapStationFeatureToStation(StationDetailsContract sdc)
{
return new Data.Entities.Station
{
Id = sdc.Id.ToString(),
TmsNumber = sdc.Properties.TmsNumber,
Name = sdc.Properties.Name,
Names =
{
Fi = sdc.Properties.Names?.Fi ?? string.Empty,
Sv = sdc.Properties.Names?.Sv ?? sdc.Properties.Names?.Fi ?? string.Empty,
En = sdc.Properties.Names?.En ?? sdc.Properties.Names?.Fi ?? string.Empty
},
Coordinates =
{
Longitude = sdc.Geometry.Coordinates[0],
Latitude = sdc.Geometry.Coordinates[1]
},
RoadNumber = sdc.Properties.RoadAddress.RoadNumber,
RoadSection = sdc.Properties.RoadAddress.RoadSection,
Carriageway = sdc.Properties.RoadAddress.Carriageway,
Side = sdc.Properties.RoadAddress.Side,
Municipality = sdc.Properties.Municipality,
MunicipalityCode = sdc.Properties.MunicipalityCode,
Province = sdc.Properties.Province,
ProvinceCode = sdc.Properties.ProvinceCode,
Direction1Municipality = sdc.Properties.Direction1Municipality,
Direction1MunicipalityCode = sdc.Properties.Direction1MunicipalityCode,
Direction2Municipality = sdc.Properties.Direction2Municipality,
Direction2MunicipalityCode = sdc.Properties.Direction2MunicipalityCode,
FreeFlowSpeed1 = sdc.Properties.FreeFlowSpeed1,
FreeFlowSpeed2 = sdc.Properties.FreeFlowSpeed2,
DataUpdatedTime = sdc.Properties.DataUpdatedTime
};
}
0 Replies