Skip to content

[Bug] ExecuteAsync not working in Openedge 12.8 despite working in C# with same values- "Object reference not set to an instance of an object.'" #5250

@CephDigital

Description

@CephDigital

Library version used

4.71.0

.NET version

.NET Framework V4.8

Scenario

PublicClient - desktop app

Is this a new or an existing app?

This is a new app or experiment

Issue description and reproduction steps

I followed the tutorial here: https://learn.microsoft.com/en-us/entra/identity-platform/tutorial-v2-windows-desktop

I created a DLL based on the tutorial given to get an authentication token to be used in Openedge. I also made a C# test UI to check if it actually works which it does. I give it the same values in both the C# and Openedge apps and while the C# app works fine, the Openedge fails. ClientID, TenantID and scopes are all the same values. If it gets to the Interactive login, the login screen appears and lets me login but the AuthenticationResult will still give the same error. I've given the Openedge project every single assembly reference that is outputted in the build of the C# project and nothing works. Even if I close the login page, it still throws the same error.

Stack Trace:

This exception was originally thrown at this call stack:
       at Microsoft.Identity.Client.Platforms.Features.OpenTelemetry.OtelInstrumentation..ctor()
   at Microsoft.Identity.Client.PlatformsCommon.Shared.AbstractPlatformProxy.InternalGetOtelInstrumentation()
   at System.Lazy`1.CreateValue() in System\Lazy.cs:line 319
   at System.Lazy`1.LazyInitValue() in System\Lazy.cs:line 273
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.LogFailureTelemetryToOtel(String errorCodeToLog, ApiEvent apiEvent, CacheRefreshReason cacheRefreshReason)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<RunAsync>d__11.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.ExceptionServices\ExceptionDispatchInfo.cs:line 72
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices\TaskAwaiter.cs:line 88
   at Microsoft.Identity.Client.ApiConfig.Executors.ClientApplicationBaseExecutor.<ExecuteAsync>d__2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.ExceptionServices\ExceptionDispatchInfo.cs:line 72
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices\TaskAwaiter.cs:line 88
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in System.Runtime.CompilerServices\TaskAwaiter.cs:line 230
   at MailServiceWrapper.MailServiceHelper.<GetAccessTokenAsync>d__28.MoveNext() in ...\MailServiceWrapper\MailServiceHelper.cs:line 116

Relevant code snippets

var resp = Task.Run(() => GetAccessTokenAsync()).GetAwaiter().GetResult();

private async Task<(bool,string)> GetAccessTokenAsync()
{
    AuthenticationResult authResult = null;
    IPublicClientApplication app = App;
    var accounts = await app.GetAccountsAsync();
    var firstAccount = accounts.FirstOrDefault();

    if (firstAccount != null)
    {
        try
        {
            authResult = await app.AcquireTokenSilent(_scopes, firstAccount)
                .ExecuteAsync();
        }
        catch (Exception ex)
        {
            return (false, $"Error Acquiring Token Silently:{Environment.NewLine}{ex}");
        }
    }
    else
    {
        try
        {
            authResult = await app.AcquireTokenInteractive(_scopes)
                //.WithAccount(firstAccount)
                .WithPrompt(Prompt.SelectAccount)
                .ExecuteAsync();
        }
        catch (MsalException msalex)
        {
            return (false, $"Error Acquiring Token:{Environment.NewLine}{msalex}");
        }
    }

    return (true, authResult.AccessToken);
}

public void BuildApp()
{
    _app = null;
    _app = PublicClientApplicationBuilder.Create(_clientId)
        .WithAuthority(AzureCloudInstance.AzurePublic, _tenantId)
        .WithDefaultRedirectUri()
        .Build();

}

Expected behavior

In the C# test UI, I can make the method exactly like the tutorial where trying to get the token silently outputs the MsalUiRequiredException if needed and opens the login page. If the login is successful, it gives the token. If I give the same values in Openedge for the client ID, tenant ID and scopes, it shouldn't be throwing these errors related to Microsoft.Identity.Client

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions