- Compile the .NET assembly with 64-bit MATLAB Builder NE for 64-bit dependencies.
- Configure the server to run both 64-bit and 32-bit processes, ensuring 32-bit applications use a 32-bit process.
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B), Source=MathWorks.MATLAB.Types
13 views (last 30 days)
Show older comments
Reproduce:
Within a Visual Studio Windows Console app, add references to:
C:\Program Files\MATLAB\R2024b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Engine.dll
C:\Program Files\MATLAB\R2024b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll
C:\Program Files\MATLAB\R2024b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll
within your static void Main(string[] args) function, add:
MATLABEngine engine = MATLABEngine.StartMATLAB();
This will produce:
System.BadImageFormatException
HResult=0x8007000B
Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source=MathWorks.MATLAB.Types
StackTrace:
at MathWorks.MATLAB.Types.SafeHandles.ArrayFactoryHandle.array_factory_create_v2(ArrayFactoryHandle& factory)
at MathWorks.MATLAB.Types.SafeHandles.ArrayFactoryHandle.ArrayFactoryCreate()
at MathWorks.MATLAB.Types.Impl.MATLABArrayFactoryImpl..ctor()
at MathWorks.MATLAB.Types.MATLABArrayFactory.get_Default()
at MathWorks.MATLAB.Engine.MATLABEngineFactory.get_Default()
at MathWorks.MATLAB.Engine.MATLABEngine.StartMATLAB()
Any ideas what's the problem?
0 Comments
Accepted Answer
Animesh
on 6 Oct 2024
NET assemblies from MATLAB Builder NE are compiled into architecture-independent MSIL but have platform-dependent dependencies like DLLs or MEX-files. Thus, assemblies from 32-bit MATLAB can only be referenced in x86 projects. On a 64-bit server, a 32-bit web application is typically launched by a 64-bit process, but requires a 32-bit process due to its dependencies. Here are a few things you can try to resolve the exception:
You can refer to the following thread; it discusses a similar issue.
2 Comments
More Answers (0)
See Also
Categories
Find more on COM Component Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!