MultiEnvironment Login failing

In release build the login to a server usually fails 3-4 times before succeding withouth giving any feedback exception.

The code i’m using is:

try

  {

    var milestoneUri = new UriBuilder(ConnectionReference.Address).Uri;

    var userContext = MultiEnvironment.CreateSingleServerUserContext(false, Username, Password, true, milestoneUri);

    if (!MultiEnvironment.LoginUserContext(userContext, false, true))

    {

      var milestoneEx = MultiEnvironment.GetLastException(userContext);

      if (milestoneEx != null)

        throw new InvalidOperationException($"Handler {ConnectionReference} - ConnectMilestone Fail", milestoneEx);

      else

        throw new InvalidOperationException($"Handler {ConnectionReference} - ConnectMilestone Fail");

    }

    Logger.Debug($"Handler {ConnectionReference} - ConnectMilestone - Connected");

  }

  catch (ServerNotFoundMIPException snfe)

  {

    Logger.Error($"Handler {ConnectionReference} - ConnectMilestone - Server not found", snfe);

    userContext = null;

    milestoneUri = null;

    throw;

  }

  catch (InvalidCredentialsMIPException ice)

  {

    Logger.Error($"Handler {ConnectionReference} - ConnectMilestone - Invalid credentials", ice);

    userContext = null;

    milestoneUri = null;

    throw;

  }

  catch (Exception)

  {

    userContext = null;

    milestoneUri = null;

    throw;

  }

When calling is empty GetLastException please look in the log files here [C:\ProgramData\Milestone\MIPSDK.](file:C:/ProgramData/Milestone/MIPSDK.) Hopefully they will explain what is going wrong.

Have you tested our sample “System Status Client Console” (https://github.com/milestonesys/mipsdk-samples-component/tree/main/SystemStatusClientConsole)? It uses MultiEnvironment and is a good way to verify that the basic communication with the server works.