Semi-managed 32 bit DLL library loaded by C# code on windows x64.

A

A n g l e r

Hi all.

I'm having a project which includes:
1. a DLL library which consists of two crucial parts:
a) an unmanaged code with algorithms and references to other unmanaged
libraries
b) a managed wrapper

The library is compiled witch /clr switch as either 32 or 64 bit build
depending on what I need.

2. A C# interface that utilises the library (the DLL project added as a
reference)


The problem I'm facing is that I can compile all stuff successfully, x64
builds seem to kick-off fine, though x86 builds don't seem to work at
all. While launching the compiled project it ends up with the following:
The specified module could not be found. (Exception from HRESULT:
0x8007007E)

It also kept suggesting that this has something to do with mscorlib.dll.
but then I contrived something with debugging and it stopped showing this :/

Anyway, the same problem arises when I attempt to use 32 bit DLL library
in C# code compiled for 64 bit library. In a nutshell:
32 DLL + 32 C# = error
32 DLL + 64 C# = the same error which is OK here
64 DLL + 32 C# = as above
64 DLL + 64 C# = works just fine

Anyway, the project used to run on windows x86 in the past and it was
fine. As far as I can spot, there is a number of posts about the issue,
though I haven't found any explicit answer how to tackle this. So, if
you have any suggestions ...


Thanks in advance,
Peter
 
A

A n g l e r

I'm having a project which includes:
1. a DLL library which consists of two crucial parts:
a) an unmanaged code with algorithms and references to other unmanaged
libraries

Just to give you more details:
- platform: XP x64
- visual studio 2008
- CLR 2.0, 3.0, 3.5 (all fail me in the same way)
 
P

Peter Morris

I had problems loading a DLL dynamically on x64 so I had to mark my project
to build as x86 and then it worked.


--
Pete
=========================================
I use Enterprise Core Objects (Domain driven design)
http://www.capableobjects.com/
=========================================
 
A

A n g l e r

I had problems loading a DLL dynamically on x64 so I had to mark my project
to build as x86 and then it worked.

Lol, looks this is opposite situation in my case. I set up the DLL to
x86 and C# code to x86, though now it clashes. So far I've read there
may be the problem with the assemblies. It does definitely behave like
it mixed x64 with x86 at some stage ....

Erm, this previous message while launching was:
Troubleshooting Exceptions: System.BadImageFormatException

which is said here
http://msdn.microsoft.com/en-us/library/k7137bfe(VS.80).aspx

to be caused by C# running as x64. Though, in my case I've all set up as
x86!! ://
 
A

A n g l e r

Anyway, the same problem arises when I attempt to use 32 bit DLL library
in C# code compiled for 64 bit library. In a nutshell:
32 DLL + 32 C# = error
32 DLL + 64 C# = the same error which is OK here
64 DLL + 32 C# = as above
64 DLL + 64 C# = works just fine


I've just created a dummy DLL that doesn't have any references to any
other unmanaged libraries. Just a dummy unmanaged part and a wrapper. It
turns out this works fine when attached to C# x86. Now, how is it
possible that the 32 bit DLL with references to other unmanaged
libraries doesn't work with C# 32 bit compiled code? Any chance it
refers to some x64 library by mistake or so .... ?
 
J

Joachim Van den Bogaert

I once had a problem with an unmanaged dll that was compiled for x86.
I compiled the dll once for x86 and once for x64 and then used a
Factory
to provide the correct unmanaged dll depending on the IntPtr.Size
property

This solved my problem and de-coupled all the code I wrote on top of
it,

Regards,
Joachim
 
A

A n g l e r

Hiyah, thanks for the reply. See, the problem is that I have a DLL
(compiled as x86 with /clr) with references to other DLL (compiled as
x86 unmanaged), then I have C# code using all this (compiled as x86) and
it behaves like it was loading somewhere x64 code ... I'm really getting
weary of all this rubbish going on here :((
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top