0

I'm puzzled about an exception that I get in a fairly simple project from Rx.

I googled the BadImageFormatException and found it's thrown when a platform-specific assembly is attempted to be loaded into an incompatible process.

The platform settings of my project are "Any CPU" though, and System.Reactive.Core.dll itself is too, obviously.

The stack trace's top is in Rx:

enter image description here

the sources for which read

    protected override void OnNextCore(T value)
    {
        _onNext(value);
    }

_onNext being an Action<...>.

My immediate problem is that I don't know how to figure which assembly actually fails to load - the information isn't in the exception I'm getting, and I don't know where else to get it from either.

I don't think it's actually anything about Rx, but what is it?

Anyone any ideas?

EDIT 1:

Here's the result of fuslogvw on a non-debugger run, set to "show all bindings", together with the stack trace I'm getting from the exception. Setting fuslogvw to show only failed bindings gives me nothing at all.

enter image description here

EDIT 2:

I also made sure "prefer 32 bit" is set to off in all assemblies that are from me, especially the main console app.

EDIT 3:

Absolutely baffling: I now broke the solution down, removed all dependencies including rx, and copy-pasted the sources to a new solution with all projects straight out of the wizard - it's still happening.

I tried it on two other machines, still happening.

What the hell is this!?

I my desperation, here're the sources. Perhaps someone smarter than me is curious enough:

source code

John
  • 6,693
  • 3
  • 51
  • 90

2 Answers2

1

I suggest you to download Windows SDK and use fuslogvw tool to debug assembly bindings.

https://msdn.microsoft.com/en-us/library/ms717422(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx

Bhaal22
  • 715
  • 4
  • 10
1

Usually (and I don't mean always), the BadImageFormatException gets thrown when the assembly is either corrupt or the "bitness" (i.e. 32-bit, 64-bit) is different, in other words the executing assembly is compiled against a different "bitness" than the assembly being loaded.

In Visual Studio, even though you selected the Any CPU option, check to see if the Prefer 32 bit is set or not. It could be that there is still a mixture of 32-bit and 64-bit assemblies being compiled in your application.

See this for more info on the Prefer 32 bit field: What is the purpose of the "Prefer 32-bit" setting in Visual Studio 2012 and how does it actually work?

Another way to check your assemblies is to download and install a nice tool called Assembly Information which will tell you more about the .NET assembly.

Community
  • 1
  • 1
Dandré
  • 2,053
  • 3
  • 18
  • 38
  • These were indeed enabled, but unsetting it didn't change anything. Assembly Information is a cool took, but curiously it seems to be unable to open assemblies that were compiled with "prefer 32-bit". Still don't have a clue as to what's going on. I made sure I compiled everything from scratch. – John Jul 10 '16 at 13:36
  • Then the question becomes, what other platforms could it have targeted? Is it maybe compiled with a .NET that is not for Windows Desktop but for Mobile or something else perhaps? – Dandré Jul 10 '16 at 14:22
  • And the Reactive Core DLL? – Dandré Jul 10 '16 at 15:33
  • Referenced are the files in "net45", also Assembly Information gives me the same dependency on mscorlib (including PublicKeyToken) my own exe gives me. – John Jul 10 '16 at 15:45
  • Do you have colleagues that have the same problem as you with this exception? – Dandré Jul 10 '16 at 16:16
  • It's a private project, never happened to me before or read about something similar. – John Jul 10 '16 at 16:50
  • Either that or .NET. Sorry, I have no futher advice to give. – Dandré Jul 10 '16 at 19:05