How to fix "Could not load file or assembly 'VideoOS.Platform.SDK.UI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=bc60fba4a7969f89' or one of its dependencies. An attempt was made to load a program with an incorrect format."

Hi there,

I try to create a simple live video in a application.

It’s working fine if I set my platform target to x64 in visual studio 2012.

However, when I set it to x86 It throw “BadImageFormatException was unhandled” for “VideoOS.Platform.SDK.UI”.

I need to compile the application with platform target “x86”.

I got some other assembly file require to compile with platform target “x86”, else they will have a same exception issues too.

Please advice.

https://force.milestonesys.com/support/articles/en_US/How_To/Dependent-files-in-MIP-SDK

https://force.milestonesys.com/support/articles/en_US/How_To/Processor-architecture-compatibility-for-the-Milestone-Integration-Platform-MIP-SDK

Background information is in the MIP Documentation - .NET Library Initialization

Hi there,

I already download the 32-bit redistributable package of the MIP SDK.

After I replace all the file from “[C:\Program](file:C:/Program) Files (x86)\Milestone\MIPSDK\Bin”, I still have a problem to use ImageViewerControl.

I got an error for “BadImageFormatException was unhandled” for “VideoOS.Toolkit.dll” at ImageViewerControl.Connect();

“Could not load file or assembly ‘VideoOS.Toolkit.dll’ or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)”

Please advice.

Thank you.

With BadImageFormatException being an indication that the dlls are not the right bit-width, I would double-check that the dll’s from the 64 bit are removed and the new files from the 32 bit SDK are now copied to the solution and execution folder of the executable you are developing.

I did removed all the dll’s from 64bit and refer all the assembly file to the 32 bit SDK.

The outcome still the same.

Please advice.

If you re-build a sample from the MIP SDK whie using the 32 bit MIP SDK files do you observe the same?

Is the 32 bit MIP SDK version 2017R2?

I can try to reproduce it in my test servers if you see the same using a sample. Please let me know which sample is most like your app and the outcome of your testing with it.

Yes, I tried it but the result still the same.

I am using VideoViewer.csproj to test it.

The following is the step for the testing,

1)Install “MIP SDK 2017 R2”[http://download.milestonesys.com/MIPSDK/MIPSDK_Installer_2017R2.msi]

and

“MIP SDK 2017 R2 - Redistributable Installer x86”[http://download.milestonesys.com/MIPSDK/MIPSDK_Redist_Installer_x86_2017R2.msi].

2)Compile the VideoViewer[“[C:\Program](file:C:/Program) Files\Milestone\MIPSDK\ComponentSamples\VideoViewer”] with platform target “Any CPU”.

If compile with platform target “x86”,It will throw the badimageformatexceptionexception.

Could not load file or assembly ‘VideoOS.Platform.SDK.UI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=bc60fba4a7969f89’ or one of its dependencies. An attempt was made to load a program with an incorrect format.”

3)Call “[C:\Program](file:C:/Program) Files\Milestone\MIPSDK\Bin\CopyImageViewerActiveX.bat” to “[C:\Program](file:C:/Program) Files\Milestone\New folder (2)\MIPSDK\ComponentSamples\VideoViewer\bin\Debug”.

4)Run the application, It is able to retrieve the live image from camera.

5)Remove reference “VideoOS.Platform”,“VideoOS.Platform.SDK” and “VideoOS.Platform.SDK.UI”.

6)Add reference “VideoOS.Platform”,“VideoOS.Platform.SDK” and “VideoOS.Platform.SDK.UI” from “[C:\Program](file:C:/Program) Files (x86)\Milestone\MIPSDK\Bin”.

7)Set platfotm target to “x86”.

8)Call “[C:\Program](file:C:/Program) Files\Milestone\MIPSDK\Bin\CopyImageViewerActiveX.bat” to “[C:\Program](file:C:/Program) Files\Milestone\New folder (2)\MIPSDK\ComponentSamples\VideoViewer\bin\Debug”.

9)Run the application, select the camera and it will throw badimageformat exception at “_imageViewerControl1.Connect();”

"Could not load file or assembly ‘VideoOS.Toolkit.dll’ or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)"

Please advice.

You may try to register your ImageViewer.net dll manually using regsvr32, it helped me in similar situation with audio player. Also it is possible that you don’t initialize all the required dll’s in your code. And finally sometimes such mistakes happen when you don’t have proper dll’s and batch files in your project folder, MIP documentation provides information about the file used by each test project

Steps 3 and 8 are wrong.

You have the 32 bit files at [C:\Program](file:C:/Program) Files (x86)\Milestone\MIPSDK\Bin where the 32 bit redistributable have put them. Copy from this folder instead!

I do not think it is necessary to change the references (step 5 and 6) but it is necessary to use the 32 bit dlls.

It seems strange to me that you have a “\New folder (2)\” but I guess you have copied the samples and in the process made that folder.

Did it work?

Yes it did.