1

Getting this exception when trying to run any Solace app

An unhandled exception of type 'System.BadImageFormatException' occurred in Unknown Module.

Additional information: Could not load file or assembly 'SolaceSystems.Solclient.Messaging, Version=10.0.0.0, Culture=neutral, PublicKeyToken=e191a36e57c23464' or one of its dependencies. An attempt was made to load a program with an incorrect format.

If there is a handler for this exception, the program may be safely continued.

also getting warnings prior to building Warning 1 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "SolaceSystems.Solclient.Messaging, Version=10.0.0.0, Culture=neutral, , processorArchitecture=AMD64", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

Are those 2 related?

  • Possible duplicate of [System.BadImageFormatException An attempt was made to load a program with an incorrect format](https://stackoverflow.com/questions/4340362/system-badimageformatexception-an-attempt-was-made-to-load-a-program-with-an-inc) – Pavel Pája Halbich Jul 28 '17 at 11:48
  • 1
    You are building your project as `AnyCPU` target architecture, whereas `SolaceSystems.Solclient.Messaging` is built as `AMD64`. Either change architecture of your project or obtain different build of that library, compatible with project's target architecture. – Pavel Pája Halbich Jul 28 '17 at 12:07
  • @PavelPájaHalbich, no, this is issue with SolaceSystems.Solclient.Messaging nuget package. .Net framework raises the same error, however you have to do different steps to fix it – Manushin Igor Feb 20 '18 at 17:31
  • @ManushinIgor could you please let me know the steps to fix it, I am facing the same issue. – kedarK Sep 06 '19 at 10:15

4 Answers4

1

Please check, that your csproj was configured properly to use runtime-dependent libraries.

What you need to do:

  • Mark you project with proper runtime
  • Exclude obsolete targets from SolaceSystems.Solclient.Messaging package

Please use sample below:

<PropertyGroup>
  <!-- Mark you application as x86 for debugger -->
  <PlatformTarget>x86</PlatformTarget>

  <!-- Ask MSVS to use win-x86 runtime for debug/run. Check runtimes folder in the nupkg archive to see full list -->
  <RuntimeIdentifier>win-x86</RuntimeIdentifier>
  <!-- Mark you library, that it supports this runtime -->
  <RuntimeIdentifiers>win-x86</RuntimeIdentifiers>

</PropertyGroup>


<ItemGroup>
  <!-- Use new csproj format and package references, to simplify transitive dependencies -->
    <PackageReference Include="SolaceSystems.Solclient.Messaging" Version="10.1.1" >

    <!-- Exclude obsolete solace targets -->
    <ExcludeAssets>build</ExcludeAssets>
  </PackageReference>
</ItemGroup>

Please see also the same issues with other libraries:

Manushin Igor
  • 3,398
  • 1
  • 26
  • 40
0

You have a platform mismatch. You are likely to be using the x64 libraries on an x86 platform, or vice versa.

Note that the warning about mismatch of processor architecture can be safely ignored as long as you install the correct Messaging Assembly (and corresponding native library) at run-time. This warning is a reminder from visual studio to set you run-time environment properly.

Russell Sim
  • 1,693
  • 2
  • 14
  • 22
0

This solution worked for our team with a web service loading the SolaceSystems.Solclient.Messaging.dll and getting the BadImageFormatException: Under the app pool running our service, we went to advanced settings, and saw a setting "Enable 32-bit Applications" that had been set to true. Setting it back to false (the default) allowed the service to run normally. It turns out that this setting was incompatible with our mixture of 64-bit OS, Build of "Any CPU", and the Solace client library.

CNad
  • 61
  • 1
  • 4
0

Getting a similar error. Thought of sharing it.

Cannot find or open the PDB file. Exception thrown: 'System.DllNotFoundException' in SolaceSystems.Solclient.Messaging.dll at SolaceSystems.Solclient.Messaging.Native.Interop.SolaceNativeAPI.LogSetCallback(LogCallbackHandler callback, IntPtr user) at SolaceSystems.Solclient.Messaging.Native.MAdapter.MSolClientSetLogCallback(LogCallbackHandler callback, IntPtr user) Error - MAdapter: 4:01:22 PM | Error encountered in interop adapter Unable to load DLL 'libsolclient': The specified module could not be found. (Exception from HRESULT: 0x8007007E) In method: Init | System.DllNotFoundException: Unable to load DLL 'libsolclient': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at SolaceSystems.Solclient.Messaging.Native.Interop.SolaceNativeAPI.LogSetCallback(LogCallbackHandler callback, IntPtr user) at SolaceSystems.Solclient.Messaging.Native.MAdapter.MSolClientSetLogCallback(LogCallbackHandler callback, IntPtr user) Exception thrown: 'SolaceSystems.Solclient.Messaging.FatalErrorException' in SolaceSystems.Solclient.Messaging.dll

rajibdotnet
  • 1,498
  • 2
  • 17
  • 29