Trouble Running OpticStudio User Extensions and Analyses

  • 22 November 2023
  • 2 replies
  • 127 views

Userlevel 3
Badge +2

There is a common error that can result from running 32-bit user extensions and user analyses in OpticStudio. The error may manifest in odd ways where an extension fails to open or has an unexpected user interface.

 

When using the ZOS-API, it will engage a dynamic-link library (DLL) called the ZOSAPI_NetHelper.dll. The function of this DLL is to help the user extension locate the installed version of OpticStudio. OpticStudio versions older than 2023 R2 suffered from an issue where the NetHelper DLL could not properly search the Windows registry if the target bit setting of the user extension did not match OpticStudio. Since OpticStudio is a 64-bit program, it might not be found if a user extension was compiled as 32-bit, which is the default for common compilers.

In short, if a user extension is compiled as 32-bit and tries to use the NetHelper to find the installation location of OpticStudio, it may fail and deliver the above error message: “OpticStudio cannot be found.” If you possess the source code and are familiar with recompiling the extension, this particular error can generally be remedied by specifying the path to the OpticStudio directory in your Program Files, as shown. However, a more robust solution is to ensure that 64-bit is the target for the compiled code (see What target bit setting should I use to compile ZOS-API extensions? | Zemax Community for more details).

initialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize( OpticStudioPath );

 

Newer releases of OpticStudio include an updated helper DLL that should work regardless of whether running a 32- or 64-bit .NET application. However, we still recommend that the extensions run as 64-bit, unless there is a specific need for 32-bit. See (What target bit setting should I use to compile ZOS-API extensions? | Zemax Community) for more information on how to compile your code in a way that is compatible with Ansys Zemax OpticStudio.

There could be a situation where you have the latest version of OpticStudio installed, but you are still observing errors or unexpected behavior. In this case, it is possible that the NetHelper DLL was not updated correctly. The easiest way to be sure is to follow these steps:

  1. Uninstall ALL OpticStudio software (both Ansys and Legacy).
  2. Go to Documents\Zemax\License and delete the "version.log" file. (This directory may be located elsewhere depending on your Setup...OpticStudio Preferences...Folders setting.)
  3. Install the latest Ansys version of OpticStudio.
  4. When you run OpticStudio for the first time, you will be prompted to update the files in your Zemax directory. Make sure that allow files to be copied into your Zemax directory.

 

Important Note: We generally recommend that you only have one version of OpticStudio installed at a time. We especially recommend not having both Ansys and Legacy versions of OpticStudio installed on the same machine. By installing multiple versions, you run the risk of incorrect registry settings or old versions of the ZOS-API DLLs being used.


2 replies

Userlevel 6
Badge +2

Hi Ethan,

I just want to be clear that Prefer 32-bit extensions used to work with the ZOSAPI_NetHelper.dll if Any CPU was selected; the Zemax OpticStudio had both the 32-bit and 64-bit WinReg entry points but the first Ansys OpticStudio removed the 32-bit WinReg entry point.

For Zemax OpticSTudio, the ZOSAPI_NetHelper.dll searched for the 32-bit WinReg entry, located the OpticStudio.exeZOSAPI.dll and ZOSAPI_Interfaces.dll, and then actually connected to the 64-bit version of OpticStudio. 

Can you confirm that the C# templates for all 4 example codes will be updated so the Target Platform will be x64?

Userlevel 3
Badge +2

Thank you for the comment, Michael! It is great context. We are currently working to serve the ZOS-API examples and templates through GitHub to better manage updates to the code and keep up with changes in OpticStudio or any of the supported languages. We will certainly make sure that the updated code templates have 64-bit targeted where a full solution is warranted. I will also check with our internal team to see if we can make this adjustment to the templates in OpticStudio as well for future releases. We will also revisit the extensions/analyses that are bundled with OS that have been compiled as 32-bit.

Reply