We have a project where we are using Web Api attribute routing to create custom functionalities. Now we needed to use Episerver.Forms.ServiceApi to read submitted forms data. I added Episerver.Forms.ServiceApi nuget to project and fallowed the documentation descripted in here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/forms/how-to-use-the-episerver-forms-service-api/
When I run the application I get an error: A route named 'MS_attributerouteWebApi' is already in the route collection. Route names must be unique.Parameter name: name
Apparently Episerver.Forms.ServiceApi is calling HttpConfiguration.MapHttpAttributeRoutes() and according the documentation there is no way to disable it. Episerver.Forms.ServiceApi apparently does not have similar configuration like Episerver.ServiceApi has in Web.config file where you can disable the call to HttpConfiguration.MapHttpAttributeRoutes().
So what to do? I removed HttpConfiguration.MapHttpAttributeRoutes() from our application, hoping that call from Episerver.Forms.ServiceApi would register all routes in application. That did not work and I got an error: System.InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
So what next? Mayby I can remove the 'MS_attributerouteWebApi' and call HttpConfiguration.MapHttpAttributeRoutes() from my project?
Result: This operation is not supported by 'HostedHttpRouteCollection'. HostedHttpRouteCollection is read only collection, so removing routes is supported.
So what next? I have no idea? Am I missing something obvious?
UPDATE: This did not work. Public site is working mostly, but administration is not working and Episerver.Forms.ServiceApi is not working.
I found a solution that worked for me. The problem lies in the order that is used to initialize modules. Just adding
to my module that was doing Web Api related initialization and removing my call to
I was able to get the application up and running. I haven't tested everything yet.... but it seem's to work.
You could try simply adding this to app settings:
<add key="episerver:serviceapi:maphttpattributeroutes" value="false" />
It worked for some people.
Yeah, saw that also and was experimenting with it also. I just hate fixes that have tag "works for some people..." I will test a bit more and see what combination works for me.