Search code examples
c#kinectrobotics-studio

Trying to use Kinect for Windows with C#, but I get System.BadImageFormatException


I am attempting to create a very simple Microsoft DSS program in which I subscribe to the events generated by the example Kinect DSS that implements speech recognition with the array microphone. However, I get the error seen below at runtime.

I've referenced the proxy .dll that exposes the interface, but a problem occurs at runtime.

I've tried setting my build target platform to x86, but that did not seem to fix the problem. Is there a way that I can verify that my project is being built to target x86?

Could not register types with custom serialization.: System.BadImageFormatException:
Could not load file or assembly 'file:///c:\users\ajs\microsoft robotics dev studio 4\bin\micarrayspeechrecognizer.y2011.m06.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'file:///c:\users\ajs\microsoft robotics dev studio 4\bin\micarrayspeechrecognizer.y2011.m06.dll' at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Microsoft.Dss.Services.Serializer.DataCache.LoadAssemblyFile(Uri location, Boolean cache, Boolean& inCache) at Microsoft.Dss.Services.Serializer.DataCache.RegisterCustomSerializersFromServiceAssembly(As sembly pa, AssemblyLocations locations) === Pre-bind state information === LOG: User = condor\ajs LOG: Where-ref bind. Location = c:\users\ajs\microsoft robotics dev studio 4\bin\micarrayspeechrecognizer.y2011.m06.dll LOG: Appbase = file:///C:/Users/ajs/Microsoft Robotics Dev Studio 4/bin/ LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). === LOG: This bind starts in LoadFrom load context. WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load(). LOG: Using application configuration file: C:\Users\ajs\Microsoft Robotics Dev Studio 4\bin\DssHost.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Attempting download of new URL file:///c:/users/ajs/microsoft robotics dev studio 4/bin/micarrayspeechrecognizer.y2011.m06.dll. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.


Solution

  • It turns out that what one has to do is start the program using dsshost32 rather than the default post-build dssproxy that is run by the template Visual Studio .sln for DSS nodes. This runs the DSS node on a 32-bit CLR, and the Kinect libraries work fine.

    It then seems as though a tedious series of actions is necessary in order to get code changes from Visual Studio to show up when using dsshost32:

    1. Build and run the 64-bit project until the log shows that the "DSS host cache has been updated". This takes about ten seconds on my machine.
    2. Run your DSS node with dsshost32 manually on the command line.