I need to create a list of objects parsing an XML document.
Issue appears when projecting to AdvertisementFullScreen
I receive this error:
{"Value cannot be null.\r\nParameter name: element"}
My code:
var advFs = loadedData.Element("xxx")
.Elements("advertisementsFullScreen")
.Elements("advertisement") // RESULT BELOW
.Select(x=>new AdvertisementFullScreen()
{
Id = (int)x.Element("id"),
ImageUrl = (string)x.Element("imageUrl"),
DisplayTime = new TimeSpan(0, 0, (int)x.Element("displayTime"))
}).ToList();
Result before projecting is:
[0] = <advertisement id="7001" imageUrl="C:/xxx/Test-data/data-offline/Assets/advertisementsFullScreen/1.png" displayTime="5" isSelfPromo="1"></advertisement>
int.ParseorConvert.ToInt32instead.