c# - Issue Parsing XML Documnet with Linq.Xml -


this not question nullreferenceexception. question why statement shown throwing 1 , wrong it.

i attempting parse small xml document using linq.xml , getting null reference exception when attempting create list of objects linq query

            _columndefs = (from def in filedef.descendants("columndef")                        select new columndef ()                         {                              name = def.attribute("name").value,                             type = def.attribute("type").value,                             required = bool.parse(def.attribute("required").value),                             default = def.attribute("default").value                         }).tolist<columndef>(); 

the code here fails nullreferenceexception seen here

enter image description here

i'm having trouble trying figure out if new columdef object issue or else. if new columndef why "new" operator not creating instance of object?

_columndefs defined _columndefs = new list<columndef>();

your debugger view shows current item has no default attribute. can use default = (string)def.attribute("default") have property set null if attribute not exist.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -