Solved

using Matlab's mxArray gives me a typeLoadException

Posted on 2004-08-18
9
407 Views
Last Modified: 2010-07-27
Hi there,

I recently moved my project, which calls a matlab dll, from VS6 to VS7.  I got it running like that ok.  Then I spent a while changing the program to use ADO .NET.  Now when I run functions with matlab stuff in them I get the following exception:

An unhandled exception of type 'System.TypeLoadException' occurred in MyProject.exe
Additional information: Could not load type mxArray_tag from assembly MyProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.

The exception comes up when the code tries to step into one of the functions with matlab stuff (including mxArrays and calls to stuff in the dll).

Does anyone know what causes this?  How do I make my project know about mxArray? As far as I can recall I haven't changed the project settings, or the files with the matlab stuff in them, or anything else connected to the matlab.  But I guess my memory is failing me or something, 'cause it was definitely working before, and it isn't now.

Thanks for your help.
0
Comment
Question by:wilsonian
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:nonubik
Comment Utility
>The exception comes up when the code tries to step into one of the functions with matlab stuff (including mxArrays and calls to stuff in the dll).
Does those dlls are also compiled under VS7?

>my project, which calls a matlab dll
Do you link staticaly (against .lib) or dinamicaly (LoadLibrary...) ?
I think you need a VS7 compiled version of the .lib of mathlab dll you use, if you link against it.
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
>> I think you need a VS7 compiled version of the .lib of mathlab dll you use, if you link against it.
If you are referring to .lib to enable static linkage of a dll and not the .lib of a static library, then not usually, at least not with unmanaged C++ executable.  There are a few things that would force this, however.  I haven't tried a VC6 dll with managed C++ executable, so it might be different, but I wouldn't think so.

Was the new C++ a managed app before adding ADO .NET?  And what type is mxArray_tag?
0
 

Author Comment

by:wilsonian
Comment Utility
The project was unmanaged and most of it still is.  mxArray is a matlab-provided struct.
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
>> The project was unmanaged and most of it still is
But you are now #using <mscorlib.dll> and "Use Managed Extensions" is "Yes" in the project properties - correct?

How are you using the mx_Array struct in your code since the compiler thinks it is a type that should exist in the managed assembly?  I'm not sure what mxArray_tag is supposed to be.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:wilsonian
Comment Utility
>But you are now #using <mscorlib.dll> and "Use Managed Extensions" is "Yes" in the project >properties - correct?
yes.

>How are you using the mx_Array struct in your code since the compiler thinks it is a type that >should exist in the managed assembly?  I'm not sure what mxArray_tag is supposed to be.

There are several mxArray pointers declared and used in functions inside a class called MatTest.  MatTest.cpp #includes the .h file of the dll, I'm guessing that's how the compiler knows it exists.
(I'm kinda fuzzy on this because I didn't write the matlab dll or MatTest)

The mxArray struct is apparently something like this:
http://www.mit.edu/~pwb/matlab/headerdump/mxinternals.h
0
 

Author Comment

by:wilsonian
Comment Utility
Ok, that was simpler than I expected. A combination of this page:
http://www.dotnet247.com/247reference/msgs/14/72063.aspx

and this page:
http://www.mcse.ms/archive108-2003-11-115608.html

led me to the answer:  I put a line saying
struct mxArray_tag{};
in matTest.cpp, and it all worked again.
0
 
LVL 16

Expert Comment

by:nonubik
Comment Utility
Agree
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
Comment Utility
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now