Skip to content

Fix source DLL file locking during development#21

Open
petarcrncecIMP wants to merge 1 commit into
chuongmep:devfrom
petarcrncecIMP:fix/dispose-assembly-definition-prevent-file-lock
Open

Fix source DLL file locking during development#21
petarcrncecIMP wants to merge 1 commit into
chuongmep:devfrom
petarcrncecIMP:fix/dispose-assembly-definition-prevent-file-lock

Conversation

@petarcrncecIMP
Copy link
Copy Markdown

Summary

  • Dispose AssemblyDefinition in ResolveDuplicateMethod by wrapping it in a using block. Previously, Mono.Cecil held a file handle on the original DLL indefinitely, preventing MSBuild from rebuilding the plugin without closing AutoCAD.
  • Skip .dll/.pdb/.exe files in CopyGeneratedFilesBack(). Compiled assemblies never change at runtime, so copying them back to the original folder is unnecessary and can briefly lock the files.

Problem

When using CadAddinManager to load a plugin DLL, the source DLL often remained locked, forcing developers to close AutoCAD before rebuilding. The lock was intermittent — sometimes lasting seconds, sometimes minutes — because:

  1. AssemblyDefinition.ReadAssembly() opens a file handle that was never released (no Dispose call)
  2. CopyGeneratedFilesBack() copied binary files back to the build output folder, touching the original DLL

Test plan

  • Load a plugin DLL via CadAddinManager
  • Execute a command from the loaded plugin
  • Rebuild the plugin in Visual Studio without closing AutoCAD — build succeeds immediately
  • Reload the updated DLL in CadAddinManager — works correctly

🤖 Generated with Claude Code

…inaries

Two changes to prevent the source DLL from being locked after loading:

1. Wrap AssemblyDefinition (Mono.Cecil) in a `using` block so the file
   handle on the original DLL is released immediately after the command
   rename pass. Previously the handle was held indefinitely, preventing
   MSBuild from writing to the DLL during rebuild.

2. Skip .dll/.pdb/.exe files in CopyGeneratedFilesBack(). Compiled
   assemblies never change at runtime, so copying them back to the
   original folder is unnecessary and can briefly lock the files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant