2

I am running on .NET 4.6.2 and MVC v5.2.3 with the latest 3.0.1 Azure Search library. My problem is that the search index client is throwing an error with the following code. This does not occur on a different .NET 4.5 web app.

var SearchIndexClient = new SearchIndexClient(AZURE_SEARCH_SERVICE_NAME, AZURE_SEARCH_INDEX_NAME, new SearchCredentials(AZURE_SEARCH_API_KEY));

I found this article: https://github.com/dotnet/corefx/issues/11100

Which seems to be related, but the implementation of the fix doesn't work. I am not using .NET core, so that is my assumption as to why it doesn't pertain to me. I've been working on this for about a week now and with the latest Azure Search packages not fixing the errors, looking for some help here.

Full dump of the error.

Server Error in '/' Application.

Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.

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.TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.

Source Error: 

Line 390:                var SearchIndexClient = new SearchIndexClient(AZURE_SEARCH_SERVICE_NAME, AZURE_SEARCH_INDEX_NAME, new SearchCredentials(AZURE_SEARCH_API_KEY));
Line 391:                var Params = new SearchParameters()
Line 392:                {

Source File: C:\Users\~stuff\Data\Catalog\style.cs    Line: 390 

Stack Trace: 


[TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.]
Microsoft.Rest.ServiceClient`1.CreateRootHandler() +0
Microsoft.Azure.Search.SearchIndexClient..ctor(String searchServiceName, String indexName, SearchCredentials credentials) +34
WebThings.Data.Catalog.<GetByAzureSearch>d__289.MoveNext() in C:\Users\me\Documents\Source Control\Git Repos\Digger Digital\Data\Catalog\style.cs:390
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28
WebThings.Sites.Models.<SearchAzure>d__89.MoveNext() in C:\Users\me\Documents\Source Control\Git Repos\Digger Digital\Sites\Models\CategoryDisplay.cs:182
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28
WebThings.Sites.MainSite.Controllers.<Index>d__0.MoveNext() in C:\Users\me\Documents\Source Control\Git Repos\Digger Digital\Sites\MainSite\MainSite\Controllers\SearchController.cs:27
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +576
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0

Always happy to provide more details if needed.

Matty
  • 873
  • 8
  • 21
  • Given that the symptoms look exactly like those described in the GitHub issue, I'd be very surprised if it's unrelated. There were other folks on that thread targeting .NET 4.6 and having the same problem. Not sure what I can suggest other than to wait for a fix and double-check your binding redirects in the meantime. – Bruce Johnston Dec 09 '16 at 03:45
  • One year later and I'm trying to find a fix for the same problem – Matt Frear Dec 12 '17 at 14:10

1 Answers1

0

If you upgrade System.Net.Http to a version > 4.3.0 (e.g. latest is 4.3.3) then the problem goes away.

Matt Frear
  • 52,283
  • 12
  • 78
  • 86