0

Does anyone know of a way to force Glass Mapper SC to throw exceptions for mapping errors? It appears to swallow them, and I'm left with null properties and no easy way to diagnose the problem. The tutorials don't really dive deep into attribute configuration, so I'm forced to do a lot of TIAS which slows down development.

I'd also settle for any method that other users have found helpful for diagnosing mapping issues.

Example Here is the template for the items I'm retrieving and attempting to map:

UnitPlantRawOrigin Template

Here is one of the items that I am returning with my query:

Item with Sample Data

Here is the model that matches the template:

[SitecoreType(AutoMap = true)]
public class UnitDetails 
{
    //[SitecoreField("ID"), SitecoreId]
    public virtual Guid ID { get; set; }

    [SitecoreField("Pre-Recycled Percentage")]
    public virtual decimal PreConsumerRecycledPercentage { get; set; }

    [SitecoreField("Post-Recycled Percentage")]
    public virtual decimal PostConsumerRecycledPercentage { get; set; }

    public virtual Plant Plant { get; set; }

    [SitecoreField("Raw Material")]
    public virtual RawMaterial RawMaterial { get; set; }

    [SitecoreField("Raw Material Origin")]
    public virtual RawMaterialOrigin RawMaterialOrigin { get; set; }
}

Even if you forget the RawMaterial and RawMaterialOrigin properties for the moment (those don't map either), the decimal properties do not map. Also, the ID property will always be null unless I name it exactly (ID). I thought the [SitecoreField("ID"), SitecoreId] decorator was supposed to provide the hint to Glass. Here is an example of the mapped data. No exception is thrown:

Debug Screenshot - Unmapped Properties

Ken
  • 311
  • 1
  • 10
  • Glass throws some exceptions but without more info on the type of error messages you are look for. E.g. if a field doesn't exist on an item for example. – Michael Edwards Oct 29 '15 at 22:30
  • Added a specific example to OP. – Ken Nov 02 '15 at 16:24
  • I am facing same issues. I have written my own loader and map as well. Tried with fluent loaded as well as attribute loader. But the fields are always empty or null. It is bringing correct number of children but no data in children either. – Sanjay Zalke Jun 22 '16 at 09:45
  • I still haven't figured out the cause, nor how to increase logging/exception generation with Glass. I'm guessing it's either not compatible Sitecore 8 or is woefully undersupported. – Ken Jun 22 '16 at 10:56

1 Answers1

1

I understand this is old thread and might have resolved already, but as I managed to resolve this one more time (forgot to update last time :D) thought of recording this time.

I was doing upgrade to v5 of glass mapper. I followed attribute based configuration which is default. It is documented here, but on top of that I add

1) Templates on classes

[SitecoreType(AutoMap = true, TemplateId = "<Branch Id>"]

2) Id field should be declared as following in your code.

[SitecoreId]
public virtual Guid Id { get; set; }

3) Sitecore service changes as mentioned in the article using Sitecore Service (MVC / WebForm), passed lazy load as false and infer type as true in all places. This was really important step.

I hope this will help me next time I visit this issue. :D

Sanjay Zalke
  • 1,331
  • 1
  • 18
  • 25
  • Glad to hear it! We abandoned this ORM, but if we ever return to it I will try this approach. – Ken Jul 23 '19 at 23:54
  • I had abandoned in one of the project way back but this time I was committed to make this work. :D Another beast to master is Unicorn. – Sanjay Zalke Jul 24 '19 at 15:04