Skip to main content
Solved

Error using ZOS-API in Matlab

  • Jan 22, 2025 7:57 AM UTC
  • 11 replies
  • 1275 views

My codes (that were working with the 2024 version) do not work anymore with the 2025 release.
this is the error I get in the function “InitConnection()”:

Message: Could not load file or assembly 'ZemaxEngine.dll' or one of its dependencies. The dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
Source: mscorlib
HelpLink: None

Best answer by Julia

Hi bostanem,

I just updated my Matlab to Update5, I experience no error with this version. 

View original

11 replies

Prasath R
Zemax Staff
  • Zemax Staff
  • Jan 24, 2025 4:49 PM UTC

Hi Luca,

You might want to try changing the directory mentioned in this post. Hopefully, it will help.

Matlab examples failing to connect to OpticStudio | Zemax Community


  • Author
  • Monochrome
  • Jan 29, 2025 11:19 AM UTC

That part of the code works well, the error appears when I try to execute the line

app = TheConnection.CreateNewApplication()

NicoloAzzaroli

I have exactly the same issue.

Waiting for a solution from Zemax


Julia
Zemax Staff
Forum|alt.badge.img+2
  • Zemax Staff
  • Feb 7, 2025 10:26 AM UTC

Hi all,

Updating MATLAB to the latest version should resolve this issue. Please try updating and let us know how it goes.

下载 MATLAB、Simulink、Stateflow 和其他 MathWorks 产品

Julia


bostanem
  • Single Emitter
  • Mar 18, 2025 8:52 AM UTC

Hi all, 
I am facing the same problem and updating to the latest Matlab (ie version R2024b) did not solve the problem. The method CreateNewApplication()results in the same error: 

Message: Could not load file or assembly 'ZemaxEngine.dll' or one of its dependencies. A dynamic link library
(DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
Source: mscorlib
HelpLink: None

FYI, I am using OpticStudio 2025.


Julia
Zemax Staff
Forum|alt.badge.img+2
  • Zemax Staff
  • Mar 18, 2025 9:01 AM UTC

Hi bostanem,

Would you please try the version below?  

Julia 


bostanem
  • Single Emitter
  • Mar 18, 2025 9:18 AM UTC

Hi Julia, 
Thanks a lot. It seems that I can install Update 5 (and not 4). Would that be okay?


Julia
Zemax Staff
Forum|alt.badge.img+2
  • Zemax Staff
  • Answer
  • Mar 18, 2025 9:41 AM UTC

Hi bostanem,

I just updated my Matlab to Update5, I experience no error with this version. 


bostanem
  • Single Emitter
  • Mar 18, 2025 2:37 PM UTC

Thanks Julia, this seems to fix the issue for me. I appreciate your help. 


Forum|alt.badge.img
  • Infrared
  • Apr 29, 2025 1:40 PM UTC

Date: April 29, 2025.

The latest available from Matlab is now R2024b, update 6 (not 5).   When I install update 6 of Matlab, I have the same problem, using the sample scripts from Zemax:

success = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize();

returns 0 instead of a 1.

 


Prasath R
Zemax Staff
  • Zemax Staff
  • May 18, 2025 2:44 PM UTC

Hi Bowen,

Thank you for your update in the forum post. I'm sharing it here for the reference of other users.

ZOS-API Initialization Error in Matlab | Zemax Community