5

I'm trying to make a simple C# GUI that uses Matlab for its processing. I'm trying to use the Matlab application COM object for communication but am getting the following error during allocation:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in cSharpCallsMATLAB.exe

Additional information: Retrieving the COM class factory for component with CLSID {491B6189-7E9D-43F4-A7DE-C062DF7B326E} failed due to the following error: 80080005.

Earlier I create the necessary object:

private MLApp.MLAppClass ml;

and assign it in the form constructor:

ml = new MLApp.MLAppClass();

and the program hangs on that line and returns an error after about 5 seconds.

I've looked around but can't seem to fix this problem. Does anyone have any advice on how to get C# to successfully connect to Matlab?

Thanks!

Pascal Qyy
  • 4,442
  • 4
  • 31
  • 46
bsripgh
  • 51
  • 1
  • 2

1 Answers1

3

First of all, take a look here:

If it don't help, try to Enable Unsafe Mode, it may solve some problems with com objects.

Community
  • 1
  • 1
Pascal Qyy
  • 4,442
  • 4
  • 31
  • 46
  • I had followed the form that one of the examples I found used, and the strange thing is that the exact same program works on one system (it launches the Matlab command window and executes instructions) but gives me the 80080005 error on the other. Could you think of any possible reasons C# could have trouble contacting Matlab on one computer and not another? – bsripgh Nov 28 '10 at 17:54
  • FYI, the simple program I'm testing with is the following: – bsripgh Nov 28 '10 at 17:54
  • namespace WindowsFormsApplication1 { public partial class Form1 : Form { private MLApp.MLAppClass ml; public Form1() { InitializeComponent(); ml = new MLApp.MLAppClass(); } private void button1_Click(object sender, EventArgs e) { ml.Execute("imagesc(double(rand(50)))"); } } } – bsripgh Nov 28 '10 at 17:55
  • I had some problem with code who work properly on Vista 64 and throw an exception on XP 32... This code was executing some batch command line in an hidden console. I never found why, I just show the console, and it work. It work also if I enable unsafe mode strangely... – Pascal Qyy Nov 29 '10 at 05:34
  • What are the specs of your 2 config (OS, 32/64, .Net version...) ? – Pascal Qyy Nov 29 '10 at 05:35