CORS Issue with REST Services

I’ve got an oddball CORS issue and I’m wondering if anyone else has run into it before. (Pinging @bconner and @Olga. Thanks in advance!)

I’m getting the following error when trying to access REST services in my production environment.

Method not found: ‘Void Microsoft.Owin.Cors.CorsPolicyProvider.set_PolicyResolver(System.Func2<Microsoft.Owin.IOwinRequest,System.Threading.Tasks.Task1<System.Web.Cors.CorsPolicy>>)’.

REST is functional in my Training DB and the Web.Config’s are the same, aside from the instance-specific stuff. I’m at a bit of a loss honestly.

Thanks so much to anyone that can shed some light on this one.

The full error is below:

Method not found: ‘Void Microsoft.Owin.Cors.CorsPolicyProvider.set_PolicyResolver(System.Func2<Microsoft.Owin.IOwinRequest,System.Threading.Tasks.Task1<System.Web.Cors.CorsPolicy>>)’.
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.MissingMethodException: Method not found: ‘Void Microsoft.Owin.Cors.CorsPolicyProvider.set_PolicyResolver(System.Func2<Microsoft.Owin.IOwinRequest,System.Threading.Tasks.Task1<System.Web.Cors.CorsPolicy>>)’.

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:

[MissingMethodException: Method not found: ‘Void Microsoft.Owin.Cors.CorsPolicyProvider.set_PolicyResolver(System.Func2<Microsoft.Owin.IOwinRequest,System.Threading.Tasks.Task1<System.Web.Cors.CorsPolicy>>)’.]
Epicor.RESTApi.ConfigureStartup.ConfigureCors(IAppBuilder app) in c:_Releases\ICE\3.1.600.0\Source\Framework\Epicor.RESTApi\Startup.cs:91
Epicor.RESTApi.<>c.b__0_1(IAppBuilder site) in c:_Releases\ICE\3.1.600.0\Source\Framework\Epicor.RESTApi\Startup.cs:28
Owin.MapWhenExtensions.MapWhen(IAppBuilder app, Func2 predicate, Action1 configuration) +168

[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) +128
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture) +142
Owin.Loader.<>c__DisplayClass12.b__b(IAppBuilder builder) +93
Owin.Loader.<>c__DisplayClass1.b__0(IAppBuilder builder) +212
Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action1 startup) +873 Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action1 startup) +51
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +101
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +135
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +160
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo handlers) +580
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo handlers, IntPtr appContext, HttpContext context) +165
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +267
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +341

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +523
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +107
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +688

1 Like

Unsure if it’s helpful but I figure I’d share:
Answer 76

Also I assume this isnt the issue since you dont have the same problem with the other server:

Thanks for the pointer. I’ve actually got CORS *'ed on both instances already. Probably should have mentioned that!

It is not CORS issue, it is something wrong with the assembly you load - it does not contain necessary class or method.
Usually it happens when your web.config does not have all assembly binding redirects and some old assembly is taken from GAC and not from ERP folder.

Thanks for the reply!
I just torched the appserver directory and deployed. That resolved the issue.

For anyone reading this in the future:
Make sure to delete appserver manually. Redeploying over the existing files did not resolve the issue.

2 Likes