November Happy Hour will be moved to Thursday December 5th.

Commerce 12.5.0: Exception when creating entry with ServiceAPI 5.1

Vote:
 

Hi,

I can no longer create entries by calling the service API. We upgraded from 11.8 to 12.2 before summer, and yesterday I updated to 12.5 but it didn't help.

Updating an existing entry works just fine.

This is the error I get:
Result: "{\"Message\":\"An error has occurred.\",\"ExceptionMessage\":\"There is no contentType registered for: EPiServer.Commerce.Catalog.ContentTypes.EntryContentBase\",\"ExceptionType\":\"System.NotSupportedException\",\"StackTrace\":\"   at EPiServer.Core.Internal.DefaultContentRepository.GetDefault[T](ContentReference parentLink, CultureInfo language)\\r\\n   at EPiServer.Core.Internal.DefaultContentRepository.GetDefault[T](ContentReference parentLink)\\r\\n   at EPiServer.ServiceApi.Commerce.Controllers.Catalog.Persistence.EntryModelCommitter.SaveCatalogEntry(Entry catalogEntry)\\r\\n   at EPiServer.ServiceApi.Commerce.Controllers.Catalog.EntryController.PostCatalogEntry(Entry catalogEntry)\\r\\n   at lambda_method(Closure , Object , Object[] )\\r\\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\\r\\n ... 

And this is the model I'm using:

var model = new Entry
{
Code = "111111",
Catalog = "Books",
EndDate = DateTime.UtcNow.AddDays(100),
EntryType = "Variant",
InventoryStatus = "Enabled",
IsActive = false,
MetaClass = "BookVariant",
Name = "Test 111111",
StartDate = DateTime.UtcNow
};

Thanks,
Rickard

#195841
Aug 09, 2018 8:33
Vote:
 

do you have BookVariant metaclass created? It sounds to me there has been a problem with it

#195842
Aug 09, 2018 10:20
Vote:
 

Screenshot of Commerce manager

Is this what you mean? Can I try to recreate it or create a new for testing?

/Rickard

#195850
Aug 09, 2018 12:33
Vote:
 

Can you try setting EntryType = "Variation"?

#195851
Aug 09, 2018 12:37
Vote:
 

I tried this and got the same error.

var model = new Entry
{
Code = "111111",
Catalog = "Books",
EndDate = DateTime.UtcNow.AddDays(100),
EntryType = "Variation",
InventoryStatus = "Enabled",
IsActive = false,
MetaClass = "BookVariant",
Name = "Test 111111",
StartDate = DateTime.UtcNow
};

#195852
Aug 09, 2018 12:40
Vote:
 

Then I agree with Quan that smthing wrong with meta class BookVariant. Can you create a similar one for testing?

#195887
Aug 10, 2018 5:00
Vote:
 

I would suggest to try these steps:

  • First restart your website to make sure the content types and metaclasses are properly mapped, and try again
  • If it still does not work, can you try to add a strongly typed content type for BookVariant?
#195891
Aug 10, 2018 9:16
Vote:
 

Hi,

I have restarted the website, still getting error.

I created a new metaclass and got the same error.
I tried with another metaclass that we created in the beginning of the project. Same error.

We have this class for BookVariant. It has worked earlier:

[CatalogContentType(
GUID = "D7C2DC51-74C7-4CB8-A6F4-79CA9A0DD980",
MetaClassName = "BookVariant",
DisplayName = "Book Variant",
Description = "Display book variant")]
public class BookVariant : ByggtjanstVariantBase
{
//properties
}

public class ByggtjanstVariantBase : VariationContent
{
}

The one thing that might have changed is BookVariant inheriting from ByggtjanstVariantBase instead of VariationContent. Could that cause problems?

Thanks,
Rickard

#195945
Aug 13, 2018 12:56
Vote:
 

That's strange. I'll try to reproduce at my side...

#195946
Aug 13, 2018 13:01
Vote:
 

Hi,

ByggtjanstVariantBase should not be the problem here.

Could you check if the contentTypeModel in the following snippet code is not null?

var metaClassId = MetaClass.Load(CatalogContext.MetaDataContext, "BookVariant");

var contentTypeModel = ServiceLocator.Current.GetInstance<MetaClassToContentTypeMap>().GetContentTypeModel(metaClassId);
#196061
Aug 17, 2018 12:12
Vote:
 

Thanks,

contentTypeModel is not null when I run your code snippet.

#196064
Aug 17, 2018 12:32
Vote:
 

And is the contentTypeModel pointed to the BookVariant class correclty? (you can check the contentTypeModel.Name)

You could also check the content type if it's correct:

var contentType = ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load(contentTypeModel);

It's weird when it throws that error while the contentTypeModel is correct. I haven't reprocedured it on my local yet...

#196068
Aug 17, 2018 12:57
Vote:
 

Hi!

I checked contentType. It returns the correct class.

#196232
Aug 22, 2018 12:23
Vote:
 

@Rickard: I'd suggest you to contact developer support service. When we are able to reproduce the problem we will be able to say more.

#196242
Aug 22, 2018 18:47
Vote:
 

I was able to look into your setup, and the investigation shows that your BookVariant (and other strongly typed content types ) were not present in the context of ServiceAPI site, which was required as ServiceAPI 5.0 switched to strongly typed content type internally).

We should probably have documented this. However to fix the problem you can have two options:

  • Either move your content types to a separated project and deploy it to bin folder of ServiceAPI, which is the preferred method 
  • Or just deploy your dll to bin folder (along with dependencies), and add this setting  <add key="episerver:serviceapi:maphttpattributeroutes" value="false" /> to appSettings of ServiceAPI web.config (which is specific to your site because yours seems to register the attribute routes itself.
#196735
Sep 10, 2018 16:19
Vote:
 

Hi!

Sorry for late reply. I had to test this several times to believe that it worked laughing and it does work now.

Thank you for your help!!

Rickard

#196909
Sep 16, 2018 22:36
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.