Skip to content

fix: deduplicate CodeDom assembly references - #1300

Open
kpkhxlgy0 wants to merge 1 commit into
CoplayDev:betafrom
kpkhxlgy0:codex/codedom-assembly-dedup
Open

fix: deduplicate CodeDom assembly references#1300
kpkhxlgy0 wants to merge 1 commit into
CoplayDev:betafrom
kpkhxlgy0:codex/codedom-assembly-dedup

Conversation

@kpkhxlgy0

@kpkhxlgy0 kpkhxlgy0 commented Jul 29, 2026

Copy link
Copy Markdown

Description

Fix CodeDom dynamic compilation failures when Unity has multiple loaded assemblies with the same simple name. The observed failure involved System.Security 2.0.0.0 and 4.0.0.0: excluding System.Security entirely avoided the duplicate-reference error but made types defined only in that assembly unavailable.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

  • Preserve the existing netstandard facade exclusions used by the CodeDom backend.
  • Deduplicate remaining CodeDom references by managed assembly simple name.
  • Prefer the exact assembly identity referenced by the most loaded assemblies, then the higher version, then a stable path tie-break.
  • Preserve System.Security instead of removing it from CodeDom references.
  • Add portable EditMode regression coverage using temporary generated assemblies, without project-specific DLL paths.

Compatibility / Package Source

  • Unity version(s) tested: Unity 2022.3.23f1 on Windows
  • Package source used (#beta, #main, tag, branch, or file:): local file checkout based on CoplayDev/unity-mcp#beta at fc70dda7
  • Resolved commit hash from Packages/packages-lock.json (if using a Git package URL): not applicable (file: checkout)

Testing/Screenshots/Recordings

  • Python tests (cd Server && uv run pytest tests/ -v)
  • Unity EditMode tests
  • Unity PlayMode tests
  • Package import/compile check
  • Not applicable (explain why in Additional Notes)

Validation in the active Unity 2022.3 project:

  • Package scripts compiled with no ExecuteCode or error CS Console entries.
  • CodeDom selected System.Security, Version=4.0.0.0 from simultaneous 2.0.0.0 and 4.0.0.0 inputs.
  • CodeDom compiled and resolved System.Security.Cryptography.ProtectedData from System.Security, Version=4.0.0.0.
  • Equivalent temporary-assembly checks preserved a file named System.Security.dll with netstandard present and selected referenced version 1.0.0.0 over unreferenced version 2.0.0.0.

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual review of the generated changes

No tool or resource surface changed.

Related Issues

None.

Additional Notes

The two Unity EditMode regression tests were added to ExecuteCodeTests.cs, but the standalone UnityMCPTests project was not opened or run locally. The active host project was used for package compilation and equivalent runtime checks.

Summary by CodeRabbit

  • Bug Fixes

    • Improved CodeDom compilation reliability when projects include multiple versions of the same assembly.
    • Preserved required security assemblies during compilation with netstandard references.
    • Added smarter assembly selection to favor the version referenced by the running Unity environment.
  • Tests

    • Added regression coverage for assembly filtering and duplicate assembly resolution.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e5f7b063-d6b3-4232-8d2f-26724a643d4d

📥 Commits

Reviewing files that changed from the base of the PR and between fc70dda and 6f4c812.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/ExecuteCode.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ExecuteCodeTests.cs

📝 Walkthrough

Walkthrough

Changes

CodeDom assembly filtering

Layer / File(s) Summary
Assembly identity filtering
MCPForUnity/Editor/Tools/ExecuteCode.cs
CodeDom filtering now deduplicates resolved assemblies by identity, preferring loaded-reference matches, then newer versions and deterministic paths, while preserving unresolved paths.
Filtering regression coverage
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ExecuteCodeTests.cs
Added compilation-based tests and helpers covering System.Security.dll preservation and duplicate assembly version selection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: scriptwonder

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: deduplicating CodeDom assembly references.
Description check ✅ Passed The description follows the template and includes the required sections, change summary, compatibility, testing, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kpkhxlgy0
kpkhxlgy0 marked this pull request as ready for review July 29, 2026 19:45
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