ImageViewerWpfControls generates NullReferenceException at the time of showing camera streaming

We are working “MileStone Component Integration” using MIP SDK and trying develop a 32bit WPF application that will interact with MileStone VMS. Our application will be attached as a plug-in to an existing mother application. Goal is to show the camera streaming from the plug-in application.

Now the plug-in is working fine when we tested it as an standalone WPF application. But when we attached the plug-in with the existing mother application and try to show the streaming, system encounters the following exception at the time of running the statement: _imageViewerControl.Initialize();

System.NullReferenceException was unhandled

HResult=-2147467261

Message=Object reference not set to an instance of an object.

Source=VideoOS.UI.Common.WPF.VideoPlayer

StackTrace:

  at VideoOS.UI.Common.WPF.VideoPlayer.Toolkit.VideoImage.VideoImageManager.VideoImageUpdateRenderingParameters(VideoImage videoImage, IRenderingParameters renderingParameters)

  at VideoOS.UI.Common.WPF.VideoPlayer.Toolkit.VideoImage.VideoImage.UpdateRenderingParameters(List\`1 renderingParameters)

  at VideoOS.UI.Common.WPF.VideoPlayer.Toolkit.ToolkitVideoSource.UpdateRenderingParameters(List\`1 renderingParameters)

  at VideoOS.Platform.SDK.UI.PlatformImageViewerWpfControl.SetBufferingParameters(String bstrBufferingParameters)

  at VideoOS.Platform.SDK.UI.PlatformImageViewerWpfControl.ImageViewerUpdateState()

  at VideoOS.Platform.SDK.UI.PlatformImageViewerWpfControl.Initialize()

  at VideoOS.Platform.Client.ImageViewerWpfControl.Initialize()

My code for the live camera streaming is as follows:

_imageViewerControl.CameraFQID = _selectedMileStoneItem.FQID;

_imageViewerControl.Initialize(); // generates the null reference exception

_imageViewerControl.Connect();

_imageViewerControl.Selected = true;

_imageViewerControl.StartLive();

EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(

                                              VideoOS.Platform.Messaging.MessageId.System.ModeChangeCommand,

                                              Mode.ClientLive), \_selectedMileStoneItem.FQID);

I was wondering what are the possible reasons for this exception.

Did you correctly initialize SDK at startup of your application?

If you look at “VideoViewer” sample, you see the following two lines:

VideoOS.Platform.SDK.Environment.Initialize();		// Initialize the standalone Environment
VideoOS.Platform.SDK.UI.Environment.Initialize();

This should be done at startup of your application and only at startup.

Sorry for delayed response, but in the meantime we were actually investigating the issue in more detailed manner and found few information that I would want to share. But before that I want to the answer of the question. We are initializing the MileStone SDK at the startup of our application:

VideoOS.Platform.SDK.Environment.Initialize(); // General initialize.

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

VideoOS.Platform.SDK.Export.Environment.Initialize(); // Initialize recordings access

Now, I would want to re-explain my issue as briefly as possible.

We are trying to develop a 32bit plug-in using WPF(on top of .NET 4.6.2) using C#. Our goals are:

1. Using MIP SDK, implement the MileStone “Component Integration” with our plug-in so that the plug-in can communicate with MileStone VMS and able to show the camera feed within itself. To show camera feed, we have used “ImageViewerWpfControl” inside our application. We have already achieved this goal. Camera streaming is coming nicely in our application.

2. We have an existing Mother Application and our next goal is to host our WPF plug-in from that mother application. Now the Mother Application is written in C++ and here the problem arises. From the Mother Application, the plug-in is successfully able to communicate with VMS, but at the time of showing camera streaming, “ImageViewerWpfControl” generates a null value exception:

_imageViewerControl.Initialize(); // generates the null reference exception

System.NullReferenceException was unhandled

HResult=-2147467261

Message=Object reference not set to an instance of an object.

Source=VideoOS.UI.Common.WPF.VideoPlayer

We have also a miniature version of the Mother Application, used for testing during development. This miniature version is a .NET WPF application and our plug-in is working perfectly from inside the miniature version.

After our research, it seems to us that Milestone “ImageViewerWpfControl” behaves differently when loaded in the process space/memory of a C++ based application than when loaded into the process space/memory of the .NET based host application.

We have searched the Internet and found a information about CopyMediaCpp.bat file. We have put the following commands in the Post Build event of our plug-in but the issue is still there:

rem cd “[C:\Program](file:C:/Program) Files\Milestone\MIPSDK\Bin\Debug”

rem call CopyMediaCpp.bat “$(TargetDir)”

I was wondering what are the possible reasons for this issue. A quick assistance would be greatly appreciated.

Milestone Development will investigate this symptom. Could you please provide your tool/application for our investigation?

Regarding CopyMediaCpp.bat that will ensure that you have the proper files for running a C++ based integration, but since your plugin is .NET I would doubt that having any effect. However, if you want to try it out you need to remove the “rem” from the beginning of each of the two lines - it basically means commenting it out.

In the (most likely) case that this does not help it would be really nice if you could provide a repro sample.

Could you please try with this hotfixed version of the SDK:

http://download.milestonesys.com/MIPSDK/HOTFIX/TFS242193/MIPSDK_Installer_2019R2.msi

Thanks Peter for the SDK. I have installed the SDK in my machine. Correct me if I am wrong, but it looks like the SDK is 64bit, where as my application is 32 bit. I was wondering is it possible for you to provide a 32bit version of the same SDK.

Hello Anirban,

The provided hotfix installer should work for both x86 and x64 installations.

Hello Simon,

Thanks for the information. I have replaced all the old dlls with the hotfix dlls but my application get stopped working completely.

It looks like if I can provide a simplified version of my application, it will be easier to investigate the problem. Keeping that in mind, I have attached a sample application that will help to reproduce the problem. The sample application is written using Visual Studio 2019, but should be able to be loaded into VS 2017. The sample application includes the following projects:

1. One .NET Plug-in project: this is a WPF application where we have done “Component Integration” using MIP SDK. Name of the project is “MilestoneXprotect”. The plug-in will be resided inside

a Host application and Host application will communicate with Milestone VMS through the plug-in.

2. A .NET Host application: Purpose of the application is to host the plug-in project. Name of the project is

WpfMilestoneClient”. The plug-in is working fine from the .NET host application. There is a button in the application “Test Milestone Plugin”. This button will instruct the plug-in to communicate with the VMS.

3. A C++/MFC Host application: Purpose of the application is same as the .NET Host application. But the plug-in is not working from this application. We want to fix this problem. This is because our original application is also a C++ application and same thing restrict the camera streaming in the original application. Name of the project is “MFCMilestoneClient”.

4. A Class Library namely “Common” that is used by the two above mentioned test host projects.

Hello Anirban,

Thank you for the sample. Unfortunately, the zip file is password protected. Could you please provide the password?

Hello Simon,

Sorry for the inconvenience. Please discard the previous file. I have uploaded a new file which is not password protected. Please download this one and unzip it and let me know if you face any other difficulties.

Thank you, I can now unpack the sample you sent and open it in VS. Can you please specify what version of the SDK this was originally built for? What error are you getting when you use the hotfix Peter provided?

Hello Simon,

We are currently using “Milestone MIP SDK 2019 R1” for Component Integration.

Regarding the hotfix SDK, our findings are mentioned below:

Whenever we used the hotfix dlls in our Plug-in, both of our hosting application(C++/MFC and .NET) are become unable to load our plug-in. Even, VS is unable to load Break Points in Plug-in. So, till now, we are unable to find out what are errors generating internally when we use hotfix SDK. We are still working on that and once we know, we will share that information with you.

One thing I forgot to mention that our Plug-in is built on .NET Framework 4.6.2 and it is a 32bit application.

Hello Anirban,

We are still investigating this issue, we will get back to you with our findings.

Hello Simon,

Thanks for the update.

Hello Anirban,

I got your solution to work when launching from C++, by copying the dll files from the hotfixed version into the Lib folder in the MilestoneXProtect project. Please try that and get back to us if you have any further problems.

BR,

Simon

Hello Simon,

I have created a Lib folder inside the Output path(..\..\TestHosts\Debug\VideoApiPlugins\MilestoneXprotect\) of the MilestoneXProtect project and paste all the hotfix dlls in there. But the C++ application is still not working. Same is true for our original Mother application(C++/MFC application) also. I was wondering is there anything that I have missed apart from copying hotfix files to lib folder.

BR,

Anirban

Not in the output path, but directly in the project …\MilestoneXprotect\MilestoneXprotect\DLLs\. I apologise for calling it a Lib folder, the folder is called DLLs. It contains versions of the MIP SDK dlls that are out of date as compared to the hotfix, if replaced with the hotfixed version I had no problems with running either version of the program (WPF or C++).

Hello Simon,

As per your suggestion, I have deleted all the old Milestone dlls from the …\MilestoneXprotect\MilestoneXprotect\DLLs\ folder and paste the hotfix dlls into that particular DLLs folder, but now the both the host application are failed to load the plug-in. I was wondering the reason for load failure may be the assembly bit mismatch. My application is 32bit but looks like the hotfix version is 64bit. I already discuss this point in this thread when the hotfix version was given to me for the first time. To confirm my point, today I have started debugging the Wpf host application. I put a break point on the click event handler of Test_Host button. In the source code, on line number 91, the C# statement is:

IVideoSystemPlugin instance = _VideoApiClient.GetInstanceOfVideoSystem(initParams);

When I use 32bit Milestone assemblies, after executing the statement, value of the instance is

{MilestoneXprotect.MilestoneXprotect}

[MilestoneXprotect.MilestoneXprotect]: {MilestoneXprotect.MilestoneXprotect}

HostCallbackInstance: {GCS.VideoApi.VideoApi}

InitializeSystemParameters: {GCS.VideoApi.PluginApi.Entities.InitializeSystemParameters}

Instance: {GCS.VideoApi.PluginApi.Entities.VideoSystemInstance}

InstanceId: {150209eb-9ddc-45af-b9c7-95233351a5ea}

IsInstanceInitialized: true

SystemData: {GCS.VideoApi.PluginApi.Entities.VideoSystem}

SystemTypeDefinition: {MilestoneXprotect}

But, when I use hotfix version, value of instance is null.

I have already talked with the developer who developed the original Mother application and also this sample TestHost application. He also share the same thought: 32bit 64bit compatibility issue.

I was wondering is it possible for you to share the TestHost application you are currently using. In that way, I can check why the same application is running on your system but not at my end.

Also is it possible for you to provide us a 32bit version of the hotfix assemblies.

Thanks for your time and effort.

Hello Anirban,

I have now tried two versions, the one with the hotfix originally supplied to you, and one with the latest build from our own internal build server. Both work. I have attached a 32-bit beta SDK build with the hotfix included.

If this does not resolve the issue, please get back to me.