Cannot delete .net dll used by Autocad

Cannot delete .net dll used by Autocad

Anonymous
Not applicable
3,516 Views
5 Replies
Message 1 of 6

Cannot delete .net dll used by Autocad

Anonymous
Not applicable

Howdy folks, 

 

I use a specific autocad dll that I copy into a desired directory, use the dll to do my work and then quit autocad. I then ask c# to delete the dll file that was used in Autocad. However, action is denied saying that file is in use with another process. I have already shut down autocad before trying to delete the file so I really dont know what to do. Other files created in the same folder delete fine. Any suggestions? 

 

0 Likes
Accepted solutions (1)
3,517 Views
5 Replies
Replies (5)
Message 2 of 6

fieldguy
Advisor
Advisor

Can you explain this part? >> I then ask c# to delete the dll file<<

0 Likes
Message 3 of 6

Anonymous
Not applicable
I create a file info for the required path and then use delete routine in fileinfo class to delete the dll.
0 Likes
Message 4 of 6

fieldguy
Advisor
Advisor

That means you are trying to delete a dll that is running.  If it's running it belongs to the operating system.

 

I think you need a plan b here.

 

Edit: have you checked in Task Manager?

0 Likes
Message 5 of 6

Keith.Brown
Advisor
Advisor
Accepted solution

As you know, the code that deletes the dll must not run inside of autocad since you have to delete the dll once autocad shuts down.

 

What you probably need to do is wait for the autocad process to fully finish and then add a small wait timer before you delete the dll to make sure that autocad is completely released the dll.  I have noticed that there is a few second delay between shutting down autocad and it releasing dlls.

0 Likes
Message 6 of 6

SENL1362
Advisor
Advisor

You also may consider to not load the dll from file but from memory like so:

 

1. dllStream.Read(dllContent, ...

2. importAssembly = Assembly.Load(dllContent);

3. ImportType = importAssembly.GetType(typeName); //Namespace.Class

4. importObj = Activator.CreateInstance((Type)ImportType);

5. ImportType.InvokeMember(MethodeName, bflags | BindingFlags.InvokeMethod, null, importObj, args);

 

You can delete the dll after step 1.

 

However you cannot reload the same class again in one session.

0 Likes