Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Mark 49 posts 130 karma points
    Jun 02, 2011 @ 06:48

    umbraco to linq null object issue + solution (not really)


    [InvalidCastException: Null object cannot be converted to a value type.]
       System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +9531832
       umbraco.Linq.Core.Node.NodeDataProvider.LoadFromXml(XElement xml, T node) +1958
       umbraco.Linq.Core.Node.NodeTree`1.GetEnumerator() +440
       System.Linq.WhereEnumerableIterator`1.MoveNext() +63
       System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
       System.Linq.<GetEnumerator>d__0.MoveNext() +96

    Seems that if you have a datatype with existing nodes, then make changes to the datatype (such as adding a true/false property) it will break the umbraco to linq datacontext, throwing an error when you have code in a usercontrol instantiating the collection such as 'new MyDataContext().MyDataType.First()'.

    After this the existing node data is invalid, republishing the entire site will not fix it, however going through and re-saving any Nodes that are of this doctype will fix the issue. So it looks as if when a new property for a doctype is created (or modified?) the default values for the existing node database values are not set correctly, and then this is consequently fixed on saving.


  • Olle Jacobsen 5 posts 38 karma points
    Jun 08, 2011 @ 01:55
    Olle Jacobsen

    I have the same issue, but I can't manually get through all the nodes of that data type (close to 1000). Does anyone has a suggestion to my (our) problem?

    Thanks in advance.

  • Brian 15 posts 35 karma points
    Sep 03, 2011 @ 15:12

    I got this too and your post saved the day so thanks for that!

    I "solved" the issue by going through and re-savings all the nodes individually as you suggested. Fortunately I only had a half-dozen since I'm in the process of building a news site.

    Talk about a "gotcha"!

    - Brian


  • SideSam 13 posts 33 karma points
    Sep 06, 2011 @ 16:28

    Hi Mark, 

    Thanks for solution, solved my little problem :)

  • Jon Free 14 posts 34 karma points
    Jan 07, 2012 @ 17:12
    Jon Free

    Worked for me too. Just save all the nodes and it stopped erroring

Please Sign in or register to post replies

Write your reply to: