umco / umbraco-ditto

Ditto - the friendly view-model mapper for Umbraco

Home Page:http://our.umbraco.org/projects/developer-tools/ditto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting EntryPointNotFoundException on ditto objects

rhythm-AndyJenkins opened this issue · comments

I've been running into this issue erratically on several sites I work on, and I just now traced it down to Ditto.

I've got a data type in Umbraco called Common Link. It's an Archetype, with several different fieldset types available. I created models for each of these fieldset types, and all of them implement an interface named ICommonLink.

One of the properties on ICommonLink is this:
bool IsAnchor { get; }

This property is for future use, so on all the classes which implement ICommonLink, I've implemented this property like this:
public bool IsAnchor => true;

I'm mapping these Archetype models into variables of type ICommonLink, which usually works with no issue. However, in one particular situation I'm consistently getting this error:
screen shot 2019-01-25 at 9 39 21 am

When I debugged this application, my debugger stopped on the exact line shown in the screenshot. I ran "link.GetType()" in the immediate window, and saw VS report that the "link" variable is an ArchetypeFieldSetModel, not something that implements ICommonLink.
screen-shot-debug

I'm not familiar with the flavor of magic that Ditto uses under the hood to make everything work, but here's what I think is happening: I think normally, Ditto uses reflection to enumerate properties on types and listen for requests to those properties, so that it can defer conversion until they're actually used. I think that the C# compiler takes some kind of shortcut on constant-value properties such as I'm using, which results in Ditto not seeing the property, and therefore not intercepting requests for that property. When I access other properties first, this issue doesn't occur, because those properties trigger Ditto Processing, after which the variable contains the expected object type.

Some version information for extra context:

  • Umbraco 7.12.3
  • Ditto 0.12.2

Also, I'm not sure which model Andy is working with, but he's most likely using [DittoMixedArchetype] from here: https://github.com/rhythmagency/rhythm.umbraco.ditto.archetype/blob/master/src/Rhythm.Umbraco.Ditto.Archetype/Processors/DittoMixedArchetypeAttribute.cs

That will choose the appropriate class to instantiate depending on the Archetype fieldset alias (e.g., content link, media link, external link, and so on).

And if it's a single link rather than several, it may also be getting used in combination with [DittoFirstItem] from here: https://github.com/rhythmagency/rhythm.umbraco.ditto/blob/master/src/Rhythm.Umbraco.Ditto/Processors/DittoFirstItemAttribute.cs

he's most likely using [DittoMixedArchetype]

... well, he thought he was. Turns out, he wasn't.

Sorry! This came down to me not putting the correct processors on a property.