Pergunta

I am looking into resolviong Asp.net Webapi CORS issue with Thinktecture.Identitymodel as described in this URL http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/

I am using VS2012 with .Net 4.5 I am coming across a couple of problems here:

1) This is the error I am coming across when i make a request

Attempted to access an element as a type incompatible with the array An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.

[ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.]
System.Collections.Generic.List`1.Insert(Int32 index, T item) +62
Galaxy.CorsConfig.RegisterCors(HttpConfiguration config) +99
Galaxy.WebApiApplication.Application_Start() +377

[HttpException (0x80004005): Attempted to access an element as a type incompatible with the array.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Attempted to access an element as a type incompatible with the array.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

My application pool is pointing to Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

2)My second question is after doing things as mentioned in WebApi. Do i still need to add HTTPmodule for IIS?

Its should be very easy to get going with this. I don't know what I am missing here. Any pointers are highly appreciated.

Thanks.

Foi útil?

Solução 2

I figured out that I had a version mismatch of assemblies . My actual project was in .Net 4.0 and Thinktecture was in .Net 4.5 .

Once i fixed that it worked.

Outras dicas

I had a very similar issue because Thinktecture.IdentityModel.Web 1.4 pulled in HttpClient 0.6, which references System.Net.Http* v2.0 assemblies, but the HttpHanders list in MVC needs 4.0. Once I removed the Web pkg and its dependencies, things went back to working.

Similar to Ben's solution above, this problem occurred for me with v3.5.0 of Thinktecture.IdentityModel because of an old version of System.Net.Http (2.2.13.0) referenced in my web.config and installed in the bin folder.

Removing the dependentAssembly binding from my web.config and deleting the old System.Net.Http .dll solved the problem.

This was for a .NET 4.5 project.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top