Solved

using Matlab's mxArray gives me a typeLoadException

Posted on 2004-08-18
9
409 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
ID: 11839314
>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
ID: 11842896
>> 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
ID: 11846175
The project was unmanaged and most of it still is.  mxArray is a matlab-provided struct.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 19

Expert Comment

by:drichards
ID: 11846289
>> 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
 

Author Comment

by:wilsonian
ID: 11846687
>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
ID: 11876601
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
ID: 11880031
Agree
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11920596
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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