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.
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.
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.
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.
Related
Using Visual Studio 2017, I have created an ASP.NET Core Web Application (.NET Framework). Installed the NuGets for the .NET Framework 4.5.2 dependencies, built, and published the application to my Windows Server box where I have the .NET Core 1.1.1 RunTime installed. I run my app and get the following:
PS C:\Performance_App\v.0.0.1> .\EPiServer.Social.Testing.Performance.Application
Hosting environment: Development
Content root path: C:\Performance_App\v.0.0.1
Now listening on: http://*:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 POST http://socialvm2.ep.se:5000/api/comments multipart/form-data; boundary=----WebKitFormBoundarycVrgT9gRbDmTFv78 946
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action EPiServer.Social.Testing.Performance.Application.Controllers.CommentsController.Post (EPiServer.Social.Testing.Performance.Application) in 168.0949ms
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HL3IML91HVGN": An unhandled exception was thrown by the application.
System.TypeLoadException: Could not load type 'EPiServer.Social.Common.Rest.ResponseMessageHandler' from assembly 'EPiServer.Social.Common.Rest, Version=1.2.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'.
at EPiServer.Social.Comments.Rest.HttpCommentRepository..ctor(IHttpClientFactory httpClientFactory, ICommentRequestFactory requestFactory)
at EPiServer.Social.Comments.DefaultCommentServiceFactory.GetRepository()
at EPiServer.Social.Comments.DefaultCommentServiceFactory.Create()
at EPiServer.Social.Testing.Performance.Application.Controllers.CommentsController..ctor()
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerActivator.Create(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
The .NET Framework dependency tree looks good:
Any ideas as to what this particular problem may be?
Recently some unusual errors have started appearing on our development server. We are using Jenkins to build and deploy an ASP.NET Web API that uses OWIN and up until now everything has been working correctly. However, recently we have started to intermittently see errors like the following, lightly redacted error from the Windows Event Log:
Exception information:
Exception type: EntryPointNotFoundException
Exception message: The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'Api.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
at Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup()
at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
Recycling the IIS application pool generally resolves the problem but the fact it is happening is concerning. Any ideas as to what might be causing this to happen?
I am writing an MVC 4.5 application using MVCSiteMapProvider 4.4.9.0. When developing in Visual Studio running the Visual Studio Development Server, everything works as expected. However, after publishing the project to the production server, I am running into a NullReferenceException. Here is the call stack. (Sorry, not enough reputation points to post screen shot)
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: 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.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
MvcSiteMapProvider.Reflection.MvcSiteMapNodeAttributeDefinitionProvider.GetAttributeDefinitionsForControllers(Type type) +71
MvcSiteMapProvider.Reflection.MvcSiteMapNodeAttributeDefinitionProvider.GetMvcSiteMapNodeAttributeDefinitions(IEnumerable`1 assemblies) +168
MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer.GetMvcSiteMapNodeAttributeDynamicNodeProviderNames() +105
MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer.ResolveDynamicNodeProviders() +148
MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer..ctor(ConfigurationSettings settings, IMvcContextFactory mvcContextFactory, IUrlPath urlPath) +306
MvcSiteMapProvider.DI.SiteMapLoaderContainer..ctor(ConfigurationSettings settings) +409
MvcSiteMapProvider.DI.Composer.Compose() +430
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +229
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +341
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +854
WebActivatorEx.ActivationManager.RunPostStartMethods() +40
WebActivatorEx.StartMethodCallingModule.Init(HttpApplication context) +159
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
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): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
I have done a search on this error and the ones I have found showed a completely different call stack trace.
Here is the MVC.SiteMap
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode title="Projects" controller="Project" action="Index">
<mvcSiteMapNode title="Supplier/Trade" controller="SupplierTrade" action="Index" preservedRouteParameters="pid">
<mvcSiteMapNode title="Approval Actions" controller="SupplierTrade" action="ApprovalActions" preservedRouteParameters="pid, stmid">
<mvcSiteMapNode title="Edit PMs" controller="User" action="Index" preservedRouteParameters="pid, stmid"/>
<mvcSiteMapNode title="Contractor Standard Invoice Percent" controller="ContractorStandardInvoicePercent" action="Index" preservedRouteParameters="pid, stmid"/>
<mvcSiteMapNode title="Approval Status Of CostCode" controller="ApprovalStatusOfCostCode" action="Index" preservedRouteParameters="pid, stmid"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
I keep thinking that there is some configuration setting I am missing or a file that is on my dev machine but not on the production machine as version 3.3.6 works flawlessly. Any ideas?
The error indicates there is something wrong when MvcSiteMapProvider scans your project for [MvcSiteMapNodeAttribute] nodes. Some things you could try:
If you are not using [MvcSiteMapNodeAttribute] in your application, you can disable this scanning by setting "MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" to "false" in web.config.
If you are using [MvcSiteMapNodeAttribute], make sure you add all of the assemblies where you have them defined in "MvcSiteMapProvider_IncludeAssembliesForScan", separated by commas. Make sure each name matches what is defined in the "Assembly name" field in project properties on the Application tab. This (or the "MvcSiteMapProvider_ExcludeAssembliesForScan") field is required when "MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" is "true".
If you are using "MvcSiteMapProvider_ExcludeAssembliesForScan", try switching to using "MvcSiteMapProvider_IncludeAssembliesForScan" to ensure MvcSiteMapProvider isn't picking up some assemblies that it shouldn't.
Reference: Configuring MvcSiteMapProvider
I'm creating a WebApi application using MVC 4 which needs to support oData.
I installed the package Microsoft.AspNet.WebApi.OData (Install-Package Microsoft.AspNet.WebApi.OData -Pre) as recommended but when filtering [for example: /api/cars?$filter=startswith(Name,'F')] I'm getting the exception:
{"Message":"An error has occurred.","ExceptionMessage":"Method not found: 'Int32 Microsoft.Data.OData.Query.SemanticAst.QueryNode.get_Kind()'.","ExceptionType":"System.MissingMethodException","StackTrace":" at System.Web.Http.OData.Query.Validators.FilterQueryValidator.ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.Validators.FilterQueryValidator.ValidateQueryNode(QueryNode node, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.QueryableAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"}
What I'm missing?
There was a binary incompatibility with a version of the underlying OData library that caused this issue. I'd strongly recommend using our nightly builds. Just use this command instead in your package manager console:
Install-Package Microsoft.AspNet.WebApi.OData -Source http://www.myget.org/F/aspnetwebstacknightly/ -Pre
This will also get you a version of Web API OData support that's much closer to the final release bits.
After migrating a solution from MVC 1.0.0.0 Visual Studio 2008 to MVC 2.0.0.0 Visual Studio 2010 I get the following error:
The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
Description: 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.
Exception Details: System.ArgumentException: The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
Source Error:
Line 35: protected void Application_Start()
Line 36: {
... container initialization ...
Line 38: ControllerBuilder.Current.SetControllerFactory(typeof(MyControllerFactory));
MyLib is an external shared library implemented in MVC 1.0.0.0
MyLib is an external shared library implemented in MVC 1.0.0.0
You will have to recompile (if you have the source code) or ask the author of the library to provide you a version compiled against System.Web.Mvc Version 2.0.0.0 or this won't work.
Here's workaround I've found to make work my MVC 1.0.0.0 dependency under my MVC 2.0 website migrated to Visual Studio 2010.
In the Application_start in Global.asax I just instantiated the IControllerFactory using the implementation class MyControllerFactory instead of trying to get its type:
ControllerBuilder.Current.SetControllerFactory((IControllerFactory) new MyControllerFactory());
With that error fixed, then I got another crash:
<b>Entry point was not found. </b>
<b>Description:</b> 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.
<b>Exception Details:</b> System.EntryPointNotFoundException: Entry point was not found.
<b>Source Error: </b>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
<b>Stack Trace: </b>
[EntryPointNotFoundException: Entry point was not found.] System.Web.Mvc.IControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +181
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +85
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +392
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
This was produced because the legacy MVC 1.0 library wasn't able to resolve MVC the reference to the interface in MVC 2.0 library loaded in the application.
I solved this by adding the following section in the config file to add assembly binding from System.Web.Mvc 1.0.0.0 to System.Web.Mvc 2.0.0.0:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<!-- Binding to help Common library MVC 1 code find the classes in MVC 2 -->
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
I also had to add this configuration block to the app.config file in my unit tests project to fix the broken tests.