我正在嘗試通過圖形 api 使用 Azure.Identity UsernamePasswordCredential 對 AD 進行身份驗證,但是每當我初始化憑據建構式時,它都會引發以下例外:
The method or operation is not implemented. at System.Diagnostics.Tracing.EventSource.GetSources ()
堆疊跟蹤:
System.TypeInitializationException: The type initializer for 'Azure.Core.Pipeline.LoggingPolicy' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Azure.Core.Diagnostics.AzureCoreEventSource' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
at System.Diagnostics.Tracing.EventSource.GetSources () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Diagnostics.Tracing/EventSource.cs:318
at Azure.Core.Diagnostics.AzureEventSource.DeduplicateName (System.String eventSourceName) [0x00010] in <0aa90fe0646d47bc95bff520717dbf16>:0
at Azure.Core.Diagnostics.AzureEventSource..ctor (System.String eventSourceName) [0x00000] in <0aa90fe0646d47bc95bff520717dbf16>:0
at Azure.Core.Diagnostics.AzureCoreEventSource..ctor () [0x00000] in <0aa90fe0646d47bc95bff520717dbf16>:0
at Azure.Core.Diagnostics.AzureCoreEventSource..cctor () [0x00000] in <0aa90fe0646d47bc95bff520717dbf16>:0
--- End of inner exception stack trace ---
at Azure.Core.Pipeline.LoggingPolicy..cctor () [0x00000] in <0aa90fe0646d47bc95bff520717dbf16>:0
--- End of inner exception stack trace ---
at Azure.Core.Pipeline.HttpPipelineBuilder.Build (Azure.Core.ClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy[] perCallPolicies, Azure.Core.Pipeline.HttpPipelinePolicy[] perRetryPolicies, Azure.Core.ResponseClassifier responseClassifier) [0x00164] in <0aa90fe0646d47bc95bff520717dbf16>:0
at Azure.Identity.CredentialPipeline..ctor (Azure.Identity.TokenCredentialOptions options) [0x00023] in <47110d8b120248e4b903ba2cc44741ea>:0
at Azure.Identity.CredentialPipeline.GetInstance (Azure.Identity.TokenCredentialOptions options) [0x00003] in <47110d8b120248e4b903ba2cc44741ea>:0
at Azure.Identity.UsernamePasswordCredential..ctor (System.String username, System.String password, System.String tenantId, System.String clientId, Azure.Identity.TokenCredentialOptions options, Azure.Identity.CredentialPipeline pipeline, Azure.Identity.MsalPublicClient client) [0x00069] in <47110d8b120248e4b903ba2cc44741ea>:0
at Azure.Identity.UsernamePasswordCredential..ctor (System.String username, System.String password, System.String tenantId, System.String clientId, Azure.Identity.TokenCredentialOptions options) [0x00000] in <47110d8b120248e4b903ba2cc44741ea>:0
at MyProject.GraphService.Init (System.String username, System.String password, System.String tenantId, System.String clientId, System.String eventKeyword) [0x00014] in .../MyProject/GraphService.cs:31
at MyProject.Features.Auth.AuthViewModel.InnerGetUser () [0x00077] in .../MyProject/Features/Auth/AuthViewModel.cs:57
我的代碼是 graphService 女巫是一個標準庫 v2.1,它由 Xamarin.forms 專案中的 AuthViewModel 使用。
public class AuthViewModel: BaseViewModel
{
...
private async Task InnerGetUser()
{
try
{
this.IsBusy = true;
if (string.IsNullOrEmpty(this.Email) ||
string.IsNullOrEmpty(this.Password))
throw new ValidationException("Email e password devono essere compilati");
this._graphService.Init(this.Email, this.Password,
this._settingsService.GetStringSetting(Services.Settings.TenantId),
this._settingsService.GetStringSetting(Services.Settings.ClientId),
this._settingsService.GetStringSetting(Services.Settings.EventKeyword));
var user = await this._graphService.GetUser();
this._userService.CurrentUser = new UserDto()
{
Name = user.DisplayName
};
this._userService.InvokeOnLoginDone();
}
catch (Exception e)
{
await base.ShowError(e);
}
finally
{
this.IsBusy = false;
}
}
...
}
public class GraphService: IGraphService
{
...
public void Init(string username, string password, string tenantId, string clientId, string eventKeyword)
{
this._eventKeyword = eventKeyword;
Console.WriteLine("Creo credentials provider");
var userNamePasswordCredential = new UsernamePasswordCredential(
username, password, tenantId, clientId, new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
});
Console.WriteLine("Creo graph service client");
this._graphClient = new GraphServiceClient(userNamePasswordCredential);
}
...
}
奇怪的是,它在 net5 中的控制臺應用程式上運行良好。
掘金:
- Xamarin.forms 5.0.0.2125,
- Azure.Identity 1.4.1,
- Microsoft.Graph 4.6.0
環境:
- mac 作業系統 11.6
- Visual Studio for mac 8.10.10 (build 8)
軟體開發工具包:
- .NET 5.0.401,
- 單聲道 6.12.0.140,
- Xamarin.iOS 15.0.0.6。
有任何想法嗎?
謝謝。
uj5u.com熱心網友回復:
我遇到了類似的問題,Azure.Storage.Blobs 遇到了例外
System.TypeInitializationException: The type initializer for 'Azure.Core.Pipeline.LoggingPolicy' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Azure.Core.Diagnostics.AzureCoreEventSource' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
我通過安裝Azure.Core解決了它。我希望它可能對你有用。
uj5u.com熱心網友回復:
我將此作為 Not an answer 發布,因為我遇到了同樣的問題并且我嘗試了這個但沒有成功。我嘗試將所有診斷選項設定為 false。它確實有效果,因為當我創建 BlobServiceClient 時它停止拋出例外,但現在當我迭代列出 Blob 的結果時它拋出 System.NotImplementedException。
ClientSecretCredentialOptions options = new ClientSecretCredentialOptions();
options.Diagnostics.IsDistributedTracingEnabled = false;
options.Diagnostics.IsLoggingContentEnabled = false;
options.Diagnostics.IsLoggingEnabled = false;
options.Diagnostics.IsTelemetryEnabled = false;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/315318.html
標籤:沙马林 xamarin.forms xamarin.ios microsoft-graph-api azure-sdk-.net
