Thursday, September 19, 2013

"This operation is only valid on generic types." Exception in Sitecore 7 (Initial release)

Have you ever run into "This operation is only valid on generic types." exception? My team has. I believe its a bug with Sitecore code where IndexFieldEnumerableConverter calls GetGenericTypeDefinition method without checking if the type of the property is in fact generic.

The reason why we ran into this issues was the type of collection properties on classes that search results from Solr are being mapped to. Initially List type was used. Updating all properties from List to IEnumerable solved the issue.

Server Error in '/' Application.
This operation is only valid on generic types.
Description: An unhandled exception occurred.
Exception Details: System.InvalidOperationException: This operation is only valid on generic types.
...
Stack Trace:
[InvalidOperationException: This operation is only valid on generic types.]
System.RuntimeType.GetGenericTypeDefinition() +13998682
Sitecore.ContentSearch.Converters.IndexFieldEnumerableConverter.GetElementType(Type destinationType) +389
Sitecore.ContentSearch.Converters.IndexFieldEnumerableConverter.GetListAndElementType(Type destinationType, Type& elementType, Type& listType) +156
Sitecore.ContentSearch.Converters.IndexFieldEnumerableConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) +288
Sitecore.ContentSearch.Converters.IndexFieldStorageValueFormatter.ReadFromIndexStorage(Object indexValue, Type destinationType) +355
Sitecore.ContentSearch.DocumentTypeMapInfo.SetProperty(Object target, String propertyName, String documentFieldName, Object value) +544
Sitecore.ContentSearch.SolrProvider.Mapping.SolrDocumentPropertyMapper.ReadDocumentFields(Dictionary`2 document, IEnumerable`1 fieldNames, DocumentTypeMapInfo documentTypeMapInfo, IEnumerable`1 virtualFieldProcessors, TElement result) +942
Sitecore.ContentSearch.DefaultDocumentMapper`1.MapToType(TDocument document, SelectMethod selectMethod, IEnumerable`1 virtualFieldProcessors, SearchSecurityOptions securityOptions) +283
Sitecore.ContentSearch.SolrProvider.<GetSearchResults>d__a.MoveNext() +977
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
System.Linq.Enumerable.ToList(IEnumerable`1 source) +80

...

Tuesday, September 17, 2013

Sitecore.ePubStudio. Taking control over ePub books creation.

I just finished working on ePub generation functionality in one of my projects. The outcome turned out to be pretty interesting. Judge for yourself: https://github.com/jcore/Sitecore.ePubStudio

Sitecore.SharedModules.ePubStudio

A tool that allows you to create ePub files using Sitecore content. You'll find this studio to be very similar in implementation to Sitecore APS Module. Indeed APS allows you to go very granular on what content to use and where in generating PDF. Unfortunately, I didn't find a way to simply extend APS to generate different output format. This tool allows you to generate book structure and html within each chapter.
The code has been tested only with Sitecore 7 and some templates use new Sitecore 7 fields. Application I was creating it for is an MVC one, hence Sitecore.Mvc.dll reference in the project.
It also depends on DotNetEpub library (https://github.com/gonzoua/DotNetEpub) which I found to be a very lean and working nicely.