2

My project Structure looks like this:

 myApp 
 -->WCFSerLib (Any CPU Deafult application) 
 -->ClassLib1 (Any CPU)
 -->ClassLib2 (x86)

When I try to execute my application Unfortuantely am getting this below error.

 System.BadImageFormatException was unhandled by user code

Is there anyway such that I can achieve the above?

Thanks

Suave Nti
  • 3,721
  • 11
  • 54
  • 78

3 Answers3

4

If I guess right than you are trying to use an x86 dll on a x64 mashine. With AnyCPU the .net framework will use the currient architecture automatically.

So your application runs as a x64 Application which tries to load a x86 libary which failes. So you have two options:

  • Set the target architeture to x86
  • Add/create a x64 libary

If you have both verions (x86/x64) somewhere in you envireonment variable the operation system will choos the correct one automatically.

rekire
  • 47,260
  • 30
  • 167
  • 264
1

I suppose that you are running your application on a x64 system.
Mixing the Platform Type in that way will cause the BFE when the WCFService Library or the ClassLib1 call methods in ClassLib2 because the first two run as 64bit processes while the latter is forced to run in x86 mode.

You should set the same platform type on every project.
Of course, the WCFService library supports only AnyCPU, so it make sense to use, for every project, the AnyCPU platform type.

If your ClassLib2 requires the use of a 32bit library (winscard.dll) and there is no 64bit version of that library, then, I think you should use a WCF Service Application instead of a Service Library. See this question

Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286
  • Agreed Only problem for me setting `CLassLib2` into Any CPU type is that I use winscard.dll in this classlib2.dll which for some reasons giving me issues with 64-Bit. – Suave Nti Oct 29 '12 at 11:22
  • I was just looking for this, I don't know if there is a 64 bit version of that DLL. If not, then I think you should use a WCF Service Application instead of Service Library. http://stackoverflow.com/questions/3755761/i-cant-compile-a-standard-wcf-service-library-in-x86-format – Steve Oct 29 '12 at 11:33
  • I even thought the same steve.. Lastly can I host a WCF service application as a windows service? – Suave Nti Oct 29 '12 at 11:54
  • Found [this on MSDN](http://msdn.microsoft.com/en-us/library/ms733069(v=vs.100).aspx), but I don't know if you could avoid the 64bit limitation of a Service Library. Need to search more. – Steve Oct 29 '12 at 12:04
0

Thank you guys,

problem was with winscard.dll it uses Handles which are Int32 .all I changed is replacing the Int32 with Int64.

Suave Nti
  • 3,721
  • 11
  • 54
  • 78