Skip to content

Issue with Missing References and mscorlib.dll Conflicts – Referencing #14 Still Not Solving the Problem #17

@ColdPlayh

Description

@ColdPlayh

Description:

First of all, thank you for developing this amazing tool! It has been incredibly helpful in my project. However, I encountered some issues during its usage.

When using Cursor (0.47.8) in Unity 2022.3.55 to instruct the Agent to implement an airplane battle game, executing multiple scripts results in compilation errors. The error messages indicate that predefined types from mscorlib.dll are being defined multiple times.
For example, this issue frequently occurs when adding script components to GameObjects or in many other scenarios.

Error Examples:

  1. Keep Code
//Keep Code
public class UnityMCPConnection
{
	....

    options.ReferencedAssemblies.Add(typeof(object).Assembly.Location); // Add mscorlib

	....
}
{
  "code": "var player = GameObject.Find(\"Player\");\nplayer.AddComponent<SpriteRenderer>();\nplayer.AddComponent<BoxCollider2D>().isTrigger = true;\nplayer.AddComponent<PlayerController>();\nDebug.Log(\"Added components to player object\");"
}
//Error Info
Failed to execute editor command: Failed to execute command: Compilation failed: The predefined type `System.Object' is defined multiple times. Using definition from `mscorlib.dll' The predefined type `System.ValueType' is defined multiple times. Using definition from `mscorlib.dll' The predefined type `System.Attribute' is defined multiple times. Using definition from `mscorlib.dll' ... The type or namespace name `BoxCollider2D' could not be found. Are you missing an assembly reference?
  1. Comment Code According to fix: remove mscorlib #14
// Attempt to comment out the code
public class UnityMCPConnection
{
	....
	
 // options.ReferencedAssemblies.Add(typeof(object).Assembly.Location); // Add mscorlib
 
	....
}
{
  "code": "var scoreText = GameObject.Find(\"UIManager/Canvas/GameplayPanel/ScoreText\");\nif (scoreText != null) {\n    var text = scoreText.AddComponent<TMPro.TextMeshProUGUI>();\n    text.text = \"Score: 0\";\n    text.fontSize = 36;\n    text.alignment = TMPro.TextAlignment.Left;\n    Debug.Log(\"ScoreText TMP component added successfully\");\n} else {\n    Debug.LogError(\"Could not find ScoreText object\");\n}"
}
//Error Info
[UnityMCP] Failed to execute editor command: Failed to execute command: Compilation failed:\nThe type or namespace name `UI' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?

Explanation:

I tried following the solution referenced in #14 , which suggested commenting out the line that adds mscorlib.dll reference. However, when I comment out the code, I encounter an error indicating that certain namespaces (such as UI) are missing, implying that required references are not found. On the other hand, when I don't comment out the code, I get compilation errors related to multiple definitions of types from mscorlib.dll.

Environment Information:

  • Unity Version: 2022.3.55
  • Node.js Version: v22.14.0
  • NPM Version: 10.9.2
  • Operating System: Windows

Attempted Solutions (Did Not Work):

  • Switched API Compatibility Level between .NET Framework and .NET Standard.
  • Change Scripting Backend to IL2CPP.
  • Deleted the Library and Temp folders from the project directory.
  • Tried different Unity versions, including 2022.3.55 and Unity 6.0.17.
  • Commented code according to fix: remove mscorlib #14.

Expected Behavior:

The Agent should be able to successfully execute the scripts without encountering mscorlib.dll conflicts, and components should be successfully added. I would appreciate any suggestions or guidance on how to resolve this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions