I have a problem with Sitecore and Glass Mapper, we are using Glass Mapper in our project and all works fine, but when trying to set an A/B testing I got an exception about null
datasource. The strange thing is that if I check the "Test the Component" window I can see that the Test Content Item field shows the wrong content item (Home):
What am I missing, could you please advise me?
This looks like it is a known issue in the MvcContext in GlassMapper v5.6.162 and earlier. As per a Slack comment by Neil Shack:-
the issue relates to the following line https://github.com/mikeedwards83/Glass.Mapper/blob/develop/Source/Glass.Mapper.Sc.Mvc/Web/Mvc/IMvcContext.cs#L173
for normal datasource items RenderingContext.CurrentOrNull.Rendering.DataSource returns a guid such as {0A275E4A-98DF-4CB3-8A7E-948F53010AE3}, but for A/B datasources it returns a string such as sitecore://{0A275E4A-98DF-4CB3-8A7E-948F53010AE3}?lang=en&ver=0 which causes line 176 to return null
A fix has been submitted as a pull request and should be fixed in a newer version soon. https://github.com/mikeedwards83/Glass.Mapper/pull/423