Solved

using Matlab's mxArray gives me a typeLoadException

Posted on 2004-08-18
9
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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