0

I have called Matlab functions from C# using COM objects. It runs but on multiple calls it gives an exception while instantiating matlab Engine Interface through COM.

//for instantiating MATLAB Engine Interface through COM

    MLApp.MLAppClass matlab = new MLApp.MLAppClass();

Exception it gives:

Unable to cast COM object of type 'MLApp.MLAppClass' to interface type 'MLApp.DIMLApp'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{669CEC93-6E22-11CF-A4D6-00A024583C19}' failed due to the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).

I'm unable to figure this out. Any help will be appreciated.

  • I believe the MATLAB COM object will, by default, create only one instance of MATLAB (I think there is a way to stop this from happening but can't remember it off the top of my head) so if you're trying to create more than one `MLAppClass` object at once it might fail. You allude to "multiple calls" in your question; why don't you just create one `MLAppClass` object and reuse it? – wakjah May 04 '13 at 12:15
  • is this relevant: [Specifying Shared or Dedicated Server](http://www.mathworks.com/help/matlab/matlab_external/specifying-a-shared-or-dedicated-server.html)? – Amro May 21 '13 at 21:56

1 Answers1

0

I had the same problem. I was using 2 private functions, creating two different matlab objects inside that functions. Then I made the matlab object global problem solved(as below). But your problem might not be the same.

 public partial class Form1 : Form
 {
        #region ----> Global Variables
        // Create the MATLAB instance 
        MLApp.MLApp matlab = new MLApp.MLApp();
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164