ContentPart not displayed in view mode (ok in edit mode)

Topics: Writing modules
Sep 13, 2013 at 12:18 PM
Hello,

I am writing my first module to design a custom content part. I followed instructions from available tutorial and I am able to create a new content item, edit its content including fields related to the content part.

However custom content of this conte part is ignored when I wnat to display the item (view mode).

Below is my code, I guess I made a mistake but I have not found where.
       protected override DriverResult Display(
   TestPart part, string displayType, dynamic shapeHelper)
        {
            UserPrincipal userAccount = _TestServices.GetAdUserAccount(part.Domain, part.Name);

            ContentShapeResult shape = ContentShape("Parts_Test", () => shapeHelper.Parts_Test(
                Name: part.Name,
                Domain: part.Domain,
                Dn: userAccount.DistinguishedName));

            return shape;
        }
<Placement>
    <Place Parts_Test="Content:10"/>
    <Place Parts_Test_Edit="Content:7.5"/>
</Placement>
And I created a file Views/Parts/Test.cshtml
<h1>Test</h1>
Name: @Model.Name
Domain: @Model.Domain
Dn: @Model.Dn
Sep 13, 2013 at 2:08 PM
Is there anything in the error logs? Your test service might be returning null, which would cause an exception during shape creation when userAccount.DistinguishedName is called.


Sep 13, 2013 at 2:28 PM
Sorry for the dummy question... Where are located error logs ?

Else I already investigated on the service side. I set a break point and it returns the expected value. I also fully remove it for test, it does not change the result.

Regards.
Sep 13, 2013 at 3:49 PM
Logs are in Orchard.Web/App_data/Logs.


Sep 14, 2013 at 5:38 PM
From the logs, I can see...
2013-09-14 18:31:19,796 [9] Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator - NullReferenceException thrown from IContentPartDriver by Test.Drivers.TestDriver
System.NullReferenceException: Object reference not set to an instance of an object.
   at Test.Drivers.TestDriver.<>c__DisplayClass3.<Display>b__2() in d:\Userfiles\xxx\Documents\Visual Studio 2012\projects\Orchard.Source.1.7\src\Orchard.Web\Modules\Test\Drivers\TestDriver.cs:line 23
Where line 23 is:
ContentShapeResult shape = ContentShape("Parts_Test", () => shapeHelper.Parts_Test(
                Name: part.Name,
                Domain: part.Domain,
                Dn: userAccount.DistinguishedName));
Sep 14, 2013 at 7:38 PM
Only NullReferenceException that may com from that expression is userAccount.DistinguishedName. Can you try with a static string instead of that, i.e. Dn: "something". You can also try making a string copy of DistinguishedName in a local variable, in case it's a scope issue and userAccount gets somehow invalid by the time shape is created (that is, when lambda function {} => shapeHelper... is called)