question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure search - Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'

See original GitHub issue

When I try to use Azure Search on .NET Framework > 4.5.2, it blows up, throwing the above exception:

public SearchServiceClient Create()
{
    return new SearchServiceClient(options.Value.ServiceName, new SearchCredentials(options.Value.SecurityKey));
}
System.TypeLoadException occurred
  HResult=0x80131522
  Message=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=<Cannot evaluate the exception source>
  StackTrace:
   at Microsoft.Rest.ServiceClient`1.CreateRootHandler()
   at Microsoft.Azure.Search.SearchServiceClient..ctor(String searchServiceName, SearchCredentials credentials)
   at Search.Index.Search.SearchClientFactory.Create() in C:\code\Search\solutions\service\Search.Index\Search\SearchClientFactory.cs:line 18

This code is in a class library compiled with .NET Framework 4.5.2. When the executable which includes the class library is also 4.5.2, the above code works. But if I upgrade the executable to 4.6 (or 4.6.1, 4.6.2, 4.7.1) then the code starts throwing the exception.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
mattfrearcommented, Dec 12, 2017

I’ve spent the last couple of hours on this before raising the issue here - and I just figured out a workaround. I’ve added the NuGet package for System.Net.Http 4.3.3 to my class library which contains the above code - and now it works.

1reaction
brjohnstmsftcommented, Jan 31, 2018

@mattfrear Thanks for confirming; I just found that issue yesterday. I’m hoping that fixing this will be a simple matter of ensuring that Microsoft.Azure.Search refers to the correct version of whatever dependency refers to System.Net.Http. First I have to repro the issue though. I’m working on that today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inheritance sec rules violated by type: 'System.Net.Http. ...
Exception Details: "System.TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types ...
Read more >
Inheritance security rules violated by type: 'System.Net.Http ...
Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or ...
Read more >
Inheritance security rules violated by type: 'System.Net.Http ...
TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility ...
Read more >
Inheritance security rules violated by type
I got the following Error message. Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either ...
Read more >
Inheritance security rules violated by type: 'System.Net.Http ...
Message: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found