app was complied on windows7, .net4.0
i put the dll: TECIT.TFORMer.dll in the app file
test-pc,i386:
server-pc,amd64:
on test-pc,i debug the app, and got the resut, log:
but on server-pc, throw exception, log:
why test-pc app :DllImport attempting to load: 'libTFORMer6.so'
but server-pc app never show the log?
thanks.
If your mono is 64 bit, you can not load a 32 bit library into it.
While the OS usually supports running 32 bit code, it applies to the whole process.
So you should either make a 64 bit library or run 32 bit mono.
Disclaimer: your question wasn't quite clear whether you are trying to use the same library on both systems.
Related
When I compile the application using "Any CPU" I am getting System.BadImageFormatException whenever I try to open a connection using Firebird embedded dll (don't ask me why I am still using this legacy DB. not my choice)
Then I thought it must be that the dll only supports 32bit mode. So I tried to compile using x86 and indeed it runs fine this time.
However when I compile using x64 the application still runs fine. This confuses me cause it clearly indicates the dll is able to load in 64bit mode.
I made couple more tests and here are the results:
Any CPU: 64 bit process. System.BadImageFormatException
x86: 32 bit process. Runs fine
x64: 64 bit process. Runs fine
Any CPU (prefer 32bit): 32 bit process. Runs fine
I thought the only magic Any CPU does is that it picks whether to launch the process in 32/64 bit mode during startup. If the application runs fine under strict 64 bit mode then I would expect Any CPU to run fine on the same 64bit machine.
I would prefer to use Any CPU (without prefer 32bit flag) still since it makes the distribution easier.
What could be causing the exception and is there a way to deal with it?
Edit:
So I tried to use reflection to get assembly info and this is the error message I got
Exception calling "GetAssemblyName" with "1" argument(s): "Could not
load file or assembly 'fbembed.dll' or one of its dependencies. The
module was expected to contain an assembly manifest." At line:1 char:1
+ [reflection.assemblyname]::GetAssemblyName("${pwd}\fbembed.dll") | fl
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : BadImageFormatException
After examining the dll's header it turns out that Nuget is the one performing the magic. If I set the target to x86/x64 nuget will include the according version of the dll during compile.
But if I target "Any CPU" nuget will pick the x86 version of the dll. Thus if I try to launch my application in 64 bit mode it will throw BIFE.
I received a Matlab Compiled .dll (targeted for a 32 bit (x86) system). I use a 64 bit system with Windows 7 on it. I am using Visual Studio IDE for making my application and import this .dll. Below is the Code.
[DllImport("Generate_Curve.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Generate_Curve", CharSet = CharSet.Ansi)]
I have seen a similar question .net Framework Error (HRESULT 0x8007000B) so I tried to change the Platform Target to x86 or Any CPU coupled with Prefer 32-bit. Still there is an Error thrown An unhandled exception of type 'System.BadImageFormatException with Additional Information as An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B). Can any one point out something that I have missed.
I received the answer from Matlab (Mathworks) that there is a bug in Matlab Compiler. If one compiles from a 64 bit Matlab in Matlab Coder for a target machine or application of 32 bit the .dll generated is highly likely to be corrupted. The solution is to compile a dll for 32bit target machine/application using a 32 bit Matlab (Matlab Coder). This issue is more of a Matlab Coder issue.
How can I use 32 dll for AnyCpu(x64). Error :
Retrieving the COM class factory for component with CLSID
{E187099F-8C5C-4723-8866-D8DBB6353ADE} failed due to the following
error: 80040153 Invalid value for registry (Exception from HRESULT:
0x80040153 (REGDB_E_INVALIDVALUE))
Is there a solution for this?
Quick answer: No. You cannot use 32bit dlls in an 64bit application.
A workaround would be to create a 32bit application, that uses the 32bit dll and then communicates with your 64bit application via IPC or something similar.
I'm trying to interop with the ImageMagick library in Mono on a Mac. I installed the ImageMagick library with MacPorts and have verified that the file libMagickWand.dylib exists in the directory /opt/local/lib. I've also created a soft link to that file in the directory /usr/local/lib.
Here's my DllImport statement:
[DllImport("libMagickWand", EntryPoint = "MagickWandGenesis")]
static extern void WandGenesis();
Here's my App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<dllmap dll="libMagickWand" target="/opt/local/lib/libMagickWand.dylib" />
</configuration>
And, at the call to WandGenesis();, I get a DllNotFoundException, with the message 'libMagickWand'.
I've read this page and I think I'm following all the rules. Is there anything else I can try?
Update:
I ran the .exe with MONO_LOG_LEVEL=debug. Here is the pertinent information:
Mono: DllImport error loading library 'dlopen(/opt/local/lib/libMagickWand.5.dylib, 9):
no suitable image found.
Did find: /opt/local/lib/libMagickWand.5.dylib: mach-o, but wrong architecture'.
wrong architecture: I'm running Snow Leopard in 32-bit mode and always have. I installed ImageMagick with MacPorts, and I installed Mono with the Mac package from mono-project.com. What would have been compiled with a different architecture?
Update:
I think I found my problem:
MacBook-Pro:lib ken$ lipo -info libMagickWand.5.dylib
Non-fat file: libMagickWand.5.dylib is architecture: x86_64
Update:
...but I'm still having issues. I can't seem to figure out how to compile ImageMagick with i386 architecture. When I try to do so using flags, it complains about other libraries that were compiled as 64-bit.
Update:
Mono on Mac OS X is 32 bit (at least usually, you can confirm that with mono --version) and you are trying to link with 64bit binary which is not possible. You have to provide 32-bit binary (or use 64-bit Mono).
Do you have the error even when only the library's file name is in the target and the library is placed appropriately (or the DYLD_LIBRARY_PATH set)? In such case please provide the output of mono executed with MONO_LOG_LEVEL=debug.
I have some old 32bit console .NET 2.0 applications that should be migrated to win2008 r2 server.
Note 1: I have one old 32bit application that doesn't load any assembly and is working correctly.
Note 2: When I start one of the applications I get
System.BadImageFormatException Could not load file or assembly error
Note 3:
Each of them are using NLog version 0.9.0.0. When I start these applications on our new server, I get following exception in nLOG.txt:
Error Could not load platform specific extensions: System.NullReferenceException: Object reference not set to an instance of an object.
at NLog.FilterFactory.AddFiltersFromAssembly(Assembly theAssembly, String prefix)
at NLog.Config.XmlLoggingConfiguration.LoadExtensionsFromAssembly(Assembly asm, String prefix)
at NLog.Config.XmlLoggingConfiguration.RegisterPlatformSpecificExtensions(String name)
Can you please help us how to solve this problem? Thank you in advance.
Deveti Putnik
Go to your project settings, and make sure you build your target to 32-bit (x86), and "All Platforms".
The problem you're seeing is a 64-bit executable trying to access a 32-bit DLL. .NET executables by default run as 64-bit on 64-bit OSes.
For point 3:Why not Upgrade NLog to 2.0, For point 2: "System.BadImageFormatException Could not load file or assembly for which assembly" can you find out assemby name causing this problem,it should be there in error message