RSS

Message: Unable to load DLL ‘libpart’: The specified procedure could not be found; Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

15 Nov

In a recent project, I was required to develop a .Net assembly DLL and use it together with COMSOL with Matlab, where Matlab serves as the hub, and the .Net Assembly provides some services, Matlab consumes it, and COMSOL finally perform FEA and output the result:

MatlabNXComsol_B

To start from scratch, I first developed the DLL assembly, and tested it, fine, no error, ok, proceed.

Then I hook the .Net DLL with Matlab, fine, done.

Next when I start COMSOL with Matlab, call the .Net DLL, there are some errors now:

MatlabNXComsol_A

It is apparent that some error occurs during UGNX calls, as the dll ‘libpart’ is required by UGNX.

I then thought of copying the dll to the bin folder of my program, but still no luck.

It is weird since without COMSOL, it works great. This means there is no bug. Why it does not work, when COMSOL joins? Emm, maybe due to x86 or x64 architecture? I am using win7 x64 version, and all the UGNX, Matlab and COMSOL are 64 bits as well. I then tried in Virtual Machine with x86 platform, but still the problem does not disappear!

Oh my…

The I googled, and found that this is usually a DllImport problem, where managed assembly tried to load C DLL, but the dll is not found.

Em, here comes another idea. I copied my DLL to UG_FOLDER\UGII, which corresponds the “UGII_ROOT_DIR” in the system variable. I guess this time, it will be able to find the required DLL then.

Now, it seems to work, as it takes quite some time to run, which I suppose UGNX initialize its required library . ………, but …

MatlabNXComsol_C

Oh my …

Since I am calling from Matlab, how can I get the LoaderExceptions property? And then, it suddenly comes to my mind that some .net assembly are located in “UGII\managed” folder, and I need to copy them to UGII folder as well ?

Haha, it works now!

Analysis: The reason why Matlab calls .net works, while  with COMSOL, it fails, is probably as follows:

  • In Matlab+ .net, the .net assembly is loaded into Matlab ‘s process, and Matlab knows how to load .net assembly, and possibly by searching the system path; and the actual location of DLL does not matter.
  • While for COMSOL + Matlab + UGNX, both Matlab and UGNX assembly are loaded into COMSOL process, where COMSOL has no knowledge about where the UGNX ‘s dlls (both managed and non-managed) are located. If there is a DLL to be loaded, only the folder where the .net assembly resides will be searched.

MatlabNXComsol_EMatlabNXComsol_D

 
2 Comments

Posted by on November 15, 2010 in CAE, Dotnet/C#

 

2 responses to “Message: Unable to load DLL ‘libpart’: The specified procedure could not be found; Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

  1. narnia

    December 11, 2010 at 6:31 am

    great post, just the kind of information I was looking for

     
  2. xinyustudio

    October 5, 2011 at 10:00 am

    Copy your own .net dll to UgII folder, and in the cmd window, type “Regasm Your.Net.Dll”, and you will see errors, if some dependent dlls are not found. Also copy these dll to UGII folder as well.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: