Why do I see "The RPC server is unavailable" or "The remote procedure call failed" when calling MATLAB from a C# client?
조회 수: 11 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2022년 3월 11일
편집: MathWorks Support Team
2024년 2월 29일
I am currently following a workflow similar to the one outlined in the following documentation:
Please run the below command in the MATLAB R2018b command window to get the release specific documentation
web(fullfile(docroot, 'matlab/matlab_external/call-matlab-function-from-c-client.html'))
My workflow evokes a routine that executes MATLAB functions (this is done using "matlab.Execute()") in a loop. Each time I call my routine in my for loop, I open a MATLAB session using "MLApp.MLApp matlab = new MLApp.MLApp();". When I wrap up with my MATLAB session I use "matlab.Quit();" to close it.
Essentially my workflow is repeatedly doing the following in a for-loop: creating a MATLAB instance, executing MATLAB functions on that MATLAB instance, and then closing that MATLAB instance.
When executing my workflow in my C# client, I am consistently running into errors that say "The RPC server is unavailable" and "The remote procedure call failed". How can I resolve these errors?
채택된 답변
MathWorks Support Team
2024년 1월 18일
편집: MathWorks Support Team
2024년 2월 29일
The reason that you are seeing the "The RPC server is unavailable" and "The remote procedure call failed" errors is that the execution of MATLAB functions from C# clients requires opening MATLAB as a COM server. It takes time for COM servers to quit, and if you try to create a new MATLAB COM server while the previous one is being terminated, the new COM server will get attached to the old COM server. This issue is exasperated because you are opening and closing your MATLAB instance in a for loop, which does not give enough time for the MATLAB instance to close. This eventually results in the error that you are seeing.
The solution is to use one MATLAB instance instead of creating a new one in each iteration of your loop. If you would like to use the approach where you create a MATLAB instance every iteration of your loop, you must put a sleep after trying to close the MATLAB instance so it has time to close.
Please use the below link to search for the required information in the current release:
https://www.mathworks.com/help/
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Write COM Applications to Work with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!