I've encountered a problem working with Umbraco 6.1.5 and uSiteBuilder 3.0.0 where when I instantiate a strongly typed DocumentType using ContentHelper all the fields defined in the DocumentType are loaded into the object but fields like Name, Id or Children aren't loaded (they're null, empty or 0).
From what I can tell it's because the ContentHelper method responsible for instantiation is calling the empty constructor for DynamicNode. Is there something I'm missing? Should I be defining constructors on my Document Types?
Here's my DocumentType:
namespace USiteBuilderTest.DocumentTypes
{
[DocumentType]
public class Home : DocumentTypeBase
{
[DocumentTypeProperty(Name = "Field 1")]
public string Field1 { set; get; }
[DocumentTypeProperty(Name = "Field 2")]
public string Field2 { set; get; }
[DocumentTypeProperty(Name = "Field 3")]
public string Field3 { set; get; }
}
}
In-case it's helpful, here's the part of the code that's calling the empty constructor:
Type typeDocType = DocumentTypeManager.GetDocumentTypeType(node.NodeTypeAlias);
if (typeDocType != null)
{
ConstructorInfo constructorInfo = typeDocType.GetConstructor(new[] { typeof(int) });
if (constructorInfo == null)
{
retVal = (DocumentTypeBase)Activator.CreateInstance(typeDocType);
}
else
{
retVal = (DocumentTypeBase)constructorInfo.Invoke(new object[] { node.Id });
}
I also experienced this problem. A solution could be to add an empty constructor and a constructor that has nodeid as input. Like this:
That did the trick for me.