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)
A few things to note that I've tried:
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.
Okay, I figured this out! :)
First things to clear up that I didn't realise:
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):
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).
It also didn't work using the interface, IContentTypeRepository? That's the preferred way.
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 :)