Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

Changing namespace of block results in error

$
0
0

Today I ran into a weird issue when refactoring code. As a result of the refactoring I changed the namespace of a block contenttype. 

This resulted in a runtime error when synchronizing the contenttypes:

ContentType with name '{0}' has a ModelType '{1}' that does not correspond to the required 'IContent'.

Which is a rather strange error because blocks do not implement IContent (at least not at compile time).

After decompiling the code responsible for generating the error: EPiServer.DataAbstraction.Internal.DefaultContentTypeRepository, I found out that the error originated from the following code in the ValidateModelType method:

 else
      {
        this._circularReferenceValidator.Analyze<ContentData>(type3);
        Type type4 = this._contentTypeBaseResolver.Resolve(contentType.Base);
        if ((object) type4 != null)
        {
          if (!type4.IsAssignableFrom(type3))
            throw new InvalidModelTypeException(type3, string.Format("ContentType with name '{0}' has a ModelType '{1}' that does not correspond to the required '{2}'.", (object) contentType.Name, (object) type3, (object) type4.Name));
        }
        else if (!typeof (IContent).IsAssignableFrom(type3))
          throw new InvalidModelTypeException(type3, string.Format("ContentType with name '{0}' has a ModelType '{1}' that does not correspond to the required '{2}'.", (object) contentType.Name, (object) type3, (object) "IContent"));
      }

The line with:

Type type4 = this._contentTypeBaseResolver.Resolve(contentType.Base);

Is using a "Base" property on the contenttype. When checking our database I saw that the column "Base" in table "[dbo].[tblContentType]" was filled with values for all Episerver contenttypes, but our project specific contenttypes all had a NULL value.

After filling the column "Base" with value "Block" for our custom blocks things started working again.

I am not sure why this error occured, it feels like an issue with an Episerver upgrade. The column was recently added after upgrading to a new Eiserver version I think (it isn't there in my current version of the Episerver Foundation project).

The comments on the Base property of the ContentType class is:

/// <summary>
/// NOTE: This is a pre-release API that is UNSTABLE and might not satisfy the compatibility requirements as denoted by its associated normal version.
/// Gets or sets the base for this content type instance (e.g. page or block or etc).
/// </summary>

:)

We are currently on version EPiServer.Framework 11.15.1.

Can someone tell me why this is happening?


Viewing all articles
Browse latest Browse all 6894

Trending Articles