使用.net 4.7和IdentityModel的Windows应用程序。它是一个windows服务:它在我的机器(windows 10)上工作得很好,但在windows 2008 r2上却不是。
public async Task<bool> ConnectAsync()
{
bool retValue = true;
try
{
var client = new DiscoveryClient(FileWatcherDefinitions.PortalBaseAddress);
var doc = await client.GetAsync();
retValue = !doc.IsError;
if (retValue)
{
var result = doc.TokenEndpoint;
var tokenClient = new TokenClient(doc.TokenEndpoint,
FileWatcherDefinitions.PortalClientName,
FileWatcherDefinitions.PortalClientPassword);
var tokenResponse = await tokenClient.RequestClientCredentialsAsync(FileWatcherDefinitions.PortalWebApiResource);
retValue = !tokenResponse.IsError;
if (retValue)
{
_httpClient = new HttpClient();
_httpClient.SetBearerToken(tokenResponse.AccessToken);
// _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenResponse.AccessToken);
}
}
}
catch(Exception exc)
{
retValue = false;
}
return retValue;
}
exception: System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'Void System.Net.Http.HttpClientExtensions.SetBearerToken(System.Net.Http.HttpClient, System.String)'.
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at RICustomerServiceFileWatcher.FileWatcherTimeManager.InitialOrderCheck()
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'Void System.Net.Http.HttpClientExtensions.SetBearerToken(System.Net.Http.HttpClient, System.String)'.
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()<---我已经看过Precompiled Azure Function throwing error on HttpClientExtensions.SetBearerToken use, CSX doesn't了,但它并没有解决我的问题:如果我使用该解决方案,就会得到另一个异常。
System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'Void IdentityModel.Client.DiscoveryClient..ctor(System.String, System.Net.Http.HttpMessageHandler)'.
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()
--- End of inner exception stack trace ---发布于 2022-01-31 08:55:14
您可能缺少了一个使用指令:
using IdentityModel.Client;https://stackoverflow.com/questions/44794384
复制相似问题