Issues when running .dll more than once

I have code that has been converted to a .dll and signed. I run it the first time for a set of components and it works just fine. I go run it a second time and it errors out. I then test the .vb file itself, and it runs just fine. If you have any insight on what the issues might be, I would greatly appreciate it.

Here is the error message:

Error in external library. See system log for details
File name: C:\Program Files\UGS\NX 7.5\UGII\NX_Prep.dll
Function name: ufusr

Start a fresh session of NX, run your code until it errors, then check the NX log file for clues as to why you got errors (the most recent error messages will be near the end of the file). You might want to add code that writes status messages to the log file to help track down errors. It is very similar to writing to the listing window.

Dim lg As LogFile = theSession.LogFile
lg.WriteLine("~ My status message ~")

It may be that the code can't find all the required NX dll files. Reference the following eng-tips thread:
http://www.eng-tips.com/viewthread.cfm?qid=291937

You might also want to search the GTAC languages forum for the error text, it might turn up some useful information.

Could it be that you haven't got a "GetUnloadOption" Function?

I usually have the following

Public Function GetUnloadOption()
Return Session.LibraryUnloadOption.Immediately
End Function

I'm not totally sure what this does but I think it releases the dll's after use.

I had the same problem as described above. I had used example code in which instead of a Module I defined a Class. I also used "Shared" instead of "Dim" and "Shared Public Sub" instead of just "Sub". I don't know which part was causing the problem but I do know that when I changed these things the problem was solved!