SDK can’t connect and returns "ConstructLoginServer:Unable to identify server type:192.168.4.201" and "VideoOS.Platform.SDK.Platform.ServerNotFoundMipException"Any ideas on what could be causing this?

We are running Milestone XProtect Professional+ 2017 R3 and I’m connecting with the latest SDK 2019 R1 however I have also tried previous version and have the same issue.

Copying the code to a new visual studio project fixes the issue for a while.

code in question is:

VideoOS.Platform.SDK.Environment.Initialize();

  VideoOS.Platform.EnvironmentManager.Instance.EnvironmentOptions\["UsePing"\] = "No";

  Uri uri = new UriBuilder(Url).Uri;

  CredentialCache credentialCache = Util.BuildCredentialCache(uri, Username, Password, "Basic");

  VideoOS.Platform.SDK.Environment.AddServer(uri, credentialCache);

  LoginSettings loginSettings = null;

  try

  {

    VideoOS.Platform.SDK.Environment.Login(uri); //<------- Fails Here

    loginSettings = LoginSettingsCache.GetLoginSettings(Url);

  }

  catch (ServerNotFoundMIPException snfe)

  {

    Message = "Server not found: " + snfe.Message;

    VideoOS.Platform.SDK.Environment.RemoveServer(uri);

  }

  catch (InvalidCredentialsMIPException ice)

  {

    Message = "Invalid credentials for: " + ice.Message;

    VideoOS.Platform.SDK.Environment.RemoveServer(uri);

  }

  catch (Exception)

  {

    Message = "Internal error connecting to: " + uri.DnsSafeHost;

    VideoOS.Platform.SDK.Environment.RemoveServer(uri);

  }

If you run one of the samples unmodified, like the Video Viewer sample, does it work for you.

You mention “VideoOS.Platform.SDK.Environment.Initialize();” do you do this more than once? The recommendation is to do this at startup together with the “VideoOS.Platform.Environment.Initialize();”. Might this explain the issue you see?

If using it multiple times make sure to use also - “VideoOS.Platform.SDK.Environment.UnInitialize();”

Hi Bo,

Thanks for answering. Yes the unmodified view sample works.

The issue is not that I can’t get it working its just that the working code keeps failing with the error I mentioned and the only way I have found to fix it is copy the exact code into a new project and then it works for a while.

I’m just trying to identify what it is I’m doing that could be causing it. It has happened repeatedly and copying into a new project always fixes it but it’s a pain doing it.

I know it’s something I’m doing but I can’t work out what it could be.

Rob

<------------------------------------ Form Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using TrussCorp.Cameras;
using TrussCorp.Functions;
using VideoOS.Platform.Login;

namespace TestForm
{
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
Thread m_thread = null;
private readonly CFunctions CFn = new CFunctions();
private LoginSettings loginSettings;
private List<VideoOS.Platform.Item> filteredCameraList;

public RadForm1()
{
InitializeComponent();
}

private void RadForm1_Load(object sender, EventArgs e)
{
m_thread = new Thread(new ThreadStart(ThreadProc));
m_thread.Start();
}

public void ThreadProc()
{
Tuple<LoginSettings, string> Rtn = CFn.LoginToServer(“CameraServerURL”.GetSettings(), “CameraServerUsername”.GetSettings(), “CameraServerPassword”.GetSettings());
if (string.IsNullOrEmpty(Rtn.Item2))
{
loginSettings = Rtn.Item1;
}
else
{
Fn.SendSMS(Rtn.Item2 + @" Security Pedestrian Monitor App on " + Dns.GetHostName(), “04xxxxxxxx”, “04xxxxxxxx”);
return;
}

filteredCameraList = CFn.GetCameraList();

int interval = 500;
int elapsed = 0;
int waitTime = 50;
try
{
while (true)
{
if (interval >= elapsed)
{
elapsed = 0;
//GetCameraImages();
}
Thread.Sleep(waitTime);
elapsed += waitTime;
}
}
catch (ThreadAbortException)
{
// we want to eat the exception because we don’t care if the
// thread has aborted since we probably did it on purpose by
// stopping the service.
}
}

private void RadForm1_FormClosing(object sender, FormClosingEventArgs e)
{
CFn.LogOut();
Environment.Exit(Environment.ExitCode);
}
}
}

<------------------------------------------------------------- Camera Functions above

public class CFunctions
{
public Tuple<LoginSettings,string> LoginToServer(string Url, string Username, string Password)
{
LogOut();
string Message = “”;

VideoOS.Platform.SDK.Environment.Initialize();
VideoOS.Platform.EnvironmentManager.Instance.EnvironmentOptions[“UsePing”] = “No”;
Uri uri = new UriBuilder(Url).Uri;
CredentialCache credentialCache = Util.BuildCredentialCache(uri, Username, Password, “Basic”);
VideoOS.Platform.SDK.Environment.AddServer(uri, credentialCache);

LoginSettings loginSettings = null;

try
{
VideoOS.Platform.SDK.Environment.Login(uri);
loginSettings = LoginSettingsCache.GetLoginSettings(Url);
}
catch (ServerNotFoundMIPException snfe)
{
Message = "Server not found: " + snfe.Message;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);

}
catch (InvalidCredentialsMIPException ice)
{
Message = "Invalid credentials for: " + ice.Message;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);
}
catch (Exception)
{
Message = "Internal error connecting to: " + uri.DnsSafeHost;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);
}

return new Tuple<LoginSettings, string> (loginSettings, Message);
}

public void LogOut()
{
try
{
VideoOS.Platform.SDK.Environment.Logout();
VideoOS.Platform.SDK.Environment.UnInitialize();
}
catch
{
// ignored
}
}

public List<VideoOS.Platform.Item> GetCameraList()
{
List<VideoOS.Platform.Item> cameraFolder = VideoOS.Platform.Configuration.Instance.GetItemsByKind(VideoOS.Platform.Kind.Camera);
List<VideoOS.Platform.Item> cameraList = FindAllCameras(cameraFolder);
List<VideoOS.Platform.Item> filteredCameraList = RemoveDuplicates(cameraList);

return filteredCameraList;
}

private List<VideoOS.Platform.Item> FindAllCameras(List<VideoOS.Platform.Item> folders)
{
List<VideoOS.Platform.Item> result = new List<VideoOS.Platform.Item>();
foreach (VideoOS.Platform.Item item in folders)
{
if (item.FQID.FolderType == VideoOS.Platform.FolderType.No)
{
if (item.FQID.Kind == VideoOS.Platform.Kind.Camera)
result.Add(item);
}
else
{
if (item.FQID.Kind == VideoOS.Platform.Kind.Server || item.FQID.Kind == VideoOS.Platform.Kind.Camera || item.FQID.Kind == VideoOS.Platform.Kind.Folder)
result.AddRange(FindAllCameras(item.GetChildren()));
}
}
return result;
}

private List<VideoOS.Platform.Item> RemoveDuplicates(List<VideoOS.Platform.Item> list)
{
Hashtable cameraObjectIds = new Hashtable();
List<VideoOS.Platform.Item> result = new List<VideoOS.Platform.Item>();
foreach (VideoOS.Platform.Item item in list)
{
if (cameraObjectIds[item.FQID.ObjectId] == null)
{
cameraObjectIds[item.FQID.ObjectId] = “AllReadyAdded”;
result.Add(item);
}
}
return result;
}
}

Can you try to do the initialize at startup only?

Is there any reason to do login at any time else than at startup?

The reference to Telerik triggered something in my memory and I found: https://developer.milestonesys.com/s/question/0D50O00004iBWpCSAW/bad-exception-when-closing-the-containing-window

Thanks Bo but I don’t believe this is the issue for the following reasons:

1. I only initialize at startup – the function I sent is only called once on load of the Form. The function returns a “LoginSettings” class which is then used for the rest of the application. I call VideoOS.Platform.SDK.Environment.Logout(); VideoOS.Platform.SDK.Environment.UnInitialize(); on “FormClosing”
2. Once the problem occurs, even if I restart the computer it still remains which seems to indicate it is not a “dispose” issue.

It looks like it is not something that other people are experiencing so I will keep looking for a solution from this end.

Rob

Is there any update regarding this issue?

I am experiencing the same issue when i run the sample’s (MultiUserEnvironment) untouched code on the following line:

VideoOS.Platform.SDK.MultiUserEnvironment.InitializeUsingUserContext(uri, textBoxUserMain.Text, textBoxPasswordMain.Text, true, true);

Error:

ConstructLoginServer:Unable to identify server type:${ip}

Does the Windows/AD user you are using work for you if logging in on the Smart Client?

Please give me details on XProtect server product and version, MIP SDK version, on the user used (AD or local Windows user) and describe how I might be able to reproduce this in the Milestone labs.

Yes it works just fine on the smart client.

Actually after restarting the machine on which the VMS products are installed, I managed to initialize the MultiUserEnvironment with the Windows/AD user, but when tried to do the same with Basic user it failed

Xprotect server product: Mileston Xprotect cooporate 2019 R3 version 13.3a

SDK version: MIPSDK 2020R1

Steps to reproduce:

  1. define a basic user
  2. add the basic user to Administrator role
  3. verify successful login with the basic user to the Management Client
  4. Try running the following line of code in a main class: VideoOS.Platform.SDK.MultiUserEnvironment.InitializeUsingUserContext(uri, textBoxUserMain.Text, textBoxPasswordMain.Text, false, true);

No there is no update. Still experiencing the issue. Very strange.