c# - Azure 搜索错误 "Inheritance security rules violated"

标签 c# azure azure-cognitive-search azure-search-.net-sdk

我正在 .NET 4.6.2 和 MVC v5.2.3 上运行,并使用最新的 3.0.1 Azure 搜索库。我的问题是搜索索引客户端使用以下代码抛出错误。在其他 .NET 4.5 Web 应用程序上不会发生这种情况。

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

我找到了这篇文章: https://github.com/dotnet/corefx/issues/11100

这似乎是相关的,但修复的实现不起作用。我没有使用 .NET core,所以这是我的假设,为什么它不适合我。我已经为此工作了大约一周,但最新的 Azure 搜索包并未修复错误,因此在此寻求一些帮助。

错误的完整转储。

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

如果需要,我们总是乐意提供更多详细信息。

最佳答案

如果您将 System.Net.Http 升级到版本 > 4.3.0(例如最新版本是 4.3.3),那么问题就会消失。

关于c# - Azure 搜索错误 "Inheritance security rules violated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048995/

相关文章:

c# - 当新控件添加到 .aspx 时,Designer.cs 不更新

c# - 我应该序列化哪些字段和属性?

azure - 如何在 CosmosDB 上查询最近 30 天的数据?

azure - 如何使用带通配符的 AzureSearch

azure - 从 ADLS Gen2(blob 文件)和 CosmosDB(自定义元数据)在 Azure 认知搜索中创建单个索引

c# - Unity中有TryResolve吗?

Azure 上的 C# MVC 应用程序 : Site works fine when freshly deployed but fails after being left idle

c# - 断言签名验证失败

azure - 元数据存储路径从 azure blob 存储编码 2 次

c# - WPF webbrowser - 下载 HTML?