3

I have a new MVC project using TokenClient from IdentityModel

var tokenClient = new TokenClient(tokenUrl, clientId, CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);

I have the nuget package in for IdentityModel and everything compiles fine. However, at runtime I get the following error.

Method not found: 'Void IdentityModel.Client.TokenClient..ctor(System.String, System.String, System.String, System.Net.Http.HttpMessageHandler, IdentityModel.Client.AuthenticationStyle)'.

The .NET version of the MVC project is 4.6.1

What can be causing this issue? I have been searching google and cannot find anything that helps. It must be something simple that i am missing.

EDIT:

initializing it by declaring the parameters explicitly does not work either.

var tokenClient = new TokenClient(tokenUrl, clientId: clientId, clientSecret: CLIENT_SECRET);// CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);

However initializing it with the one parameter works fine.

var tokenClient = new TokenClient(tokenUrl);
markblue777
  • 829
  • 3
  • 13
  • 28
  • Check out this other SO Q/A....can you confirm/deny any of these possible solutions? https://stackoverflow.com/questions/7578583/method-not-found-on-runtime – user1011627 Nov 20 '18 at 15:45
  • it is a brand new project that has a nuget reference to IdentityModel version 3.10.1. The project is just the standard mvc template project that you get when you create the project – markblue777 Nov 20 '18 at 15:55

3 Answers3

3

IdentityModel is a 3rd party library built by the creators of Identity Server. v3.10.1 definitely does have that method overload in it. I have recreated your error and the reason you are getting the error is because IdentityModel v3.10.1 is not compatible with .NET Framework 4.6.1. The creators changed the signature of that overload and made the HttpMessageHandler an optional parameter so your code will compile, but will throw this Method Not Found error at runtime. The IdentityModel project you are referencing has been archived by the guys at Identity Server so I would recommend migrating if you can.

You have a couple of options as I see it:

1) Migrate to .NET Core and leverage IdentityModel v2.

2) Downgrade your project to .NET Framework 4.5.2 (the last compatible version for IdentityModel V1)

3) Do not use this overload (as you've already found the single tokenUrl param works). I would stay away from this approach as you are likely to run into additional compatibility issues.

Basically, if you don't want to migrate to .NET Core, keep this project on 4.5.2. If you can migrate, do that instead. Identity Server is moving toward .NET Core as a whole anyway and you will get more mileage by making that leap now.

user1011627
  • 1,741
  • 1
  • 17
  • 25
  • Thanks for the reply, I thought it was going to be something simple to fix this issue. This work is for a POC so no room to learn anything new. However, looks like I am going to have to move towards .net core. – markblue777 Nov 21 '18 at 07:55
  • Welcome...if just POC I would just create the app as 4.5.2 unless you need something from .NET Framework above that version. I tested that method on that version and it does in fact work. Best of luck in whichever direction you go. – user1011627 Nov 21 '18 at 15:02
0

I encountered the same problem while working through the MVC Getting Started example for IdentityServer3. If you check the dependencies for IdentityModel v3.10.1 you'll notice that it depends on System.Net.Http (>= 4.3.3). My project had v 4.2, updating to the current version solved the problem.

rjax
  • 39
  • 5
0

If you are using ASP.Net MVC application check binding redirect of "System.Net.Http" in web.config

it should be like

 <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
 </dependentAssembly>
Airn5475
  • 2,452
  • 29
  • 51