Try our conversational search powered by Generative AI!

Error "Failed" when uploading media - "Activation error occurred while trying to get instance of type ContentTypeRepository"

Vote:
 

Locally media uploads work fine but I am getting this error in my Azure deployed app. It only happens when trying to upload media – in the UI it just says “Failed”. I have to inspect the response from the editor UI’s POST to http://xxxxxxxx.azurewebsites.net/EPiServer/CMS/FileUpload/Upload/ and it comes back with a 200 status but error message “Activation error occurred while trying to get instance of type ContentTypeRepository, key \”\””.

I’m pretty sure StructureMap is okay because everything else is working.. Is there anything special anyone knows about ContentTypeRepository that could be causing this?

(I'm running the latest Epi v10.4.2 and the code I'm playing with is based on the AlloyDemoKit)

#175352
Feb 17, 2017 0:43
Vote:
 

A few things to note that I've tried:

  • Deleting deployed files and redeploying to Azure.
  • Ensured that the StructureMap configuration is all in an InitializationModule (still as it was from AlloyDemoKit https://github.com/episerver/AlloyDemoKit/blob/master/src/AlloyDemoKit/Business/Initialization/DependencyResolverInitialization.cs).
  • Logs are set to "Error" and have no entries when this happens.

Also, everything else seems fully functional - media works otherwise. And I should say that existing media was there from when I did my initial upload to blob storage from my local - and all that existing media works correctly.

#175354
Edited, Feb 17, 2017 2:07
Vote:
 

Okay, I figured this out! :)

First things to clear up that I didn't realise:

  • This was also happening on my local, not just Azure, but it hadn't been happening previously which lead me to believe it was only broken in Azure.. Which leads me to:
  • I believe this started happening after I upgraded the solution to episerver v10.x (I was on v9.x before)

What I figured out is that if I called ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.ContentTypeRepository>() it would get:

No default Instance is registered and cannot be automatically determined for type 'EPiServer.DataAbstraction.ContentTypeRepository'

There is no configuration specified for EPiServer.DataAbstraction.ContentTypeRepository

So, I realised that something in the media upload meant there was a call to service locator asking for ContentTypeRepository. So I simply added this to my DependencyResolverInitialization code (structuremap configuration):

container.For<ContentTypeRepository>().Use<DefaultContentTypeRepository>();

And voilà! It is all happy now :)

Hope this helps someone if they stumble into this (I googled and couldn't find anyone with this exact exception).

#175356
Feb 17, 2017 6:54
Vote:
 

It also didn't work using the interface, IContentTypeRepository? That's the preferred way.

#175367
Feb 17, 2017 10:21
Vote:
 

Hi Jeroen

Yeah, quite right, IContentTypeRepository does work and is what should be used. But in my situation this error was happening when uploading media - so there must be some Episerver (or AlloyDemoKit?) code that must use "ContentTypeRepository" instead.. So since I don't think it was my code (code be wrong?) I didn't have a choice but to tell Structure Map to give the DefaultContentTypeRepository if that was requested.

Thanks for the reply :)

Matt

#175370
Feb 17, 2017 11:27
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.