Skip to content

fix: add C# library references to a csproj that has no ItemGroup - #769

Open
pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-library-add
Open

pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-library-add

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #764

Root cause: XMLManager.parse returns the <Project> root element itself, so csproj_tree.find(".//Project") (which only searches descendants) returns None when the csproj has no ItemGroup. etree.SubElement(None, "ItemGroup") then raises TypeError: Argument '_parent' has incorrect type. This happened in library_manager._add_csharp_project_to_csproj (after the library had already been written to the project config) and in the same pattern in commands/library/add.py.

Fix: create the ItemGroup directly under the parsed root. This also removes the crash for the namespaced project in the issue comment (xmlns=".../msbuild/2003"): the namespaced ItemGroup is not matched by .//ItemGroup, so a new ItemGroup is appended under the root, and lxml serializes it without an xmlns="" reset, so it stays in the MSBuild namespace.

Test: test_add_csharp_project_to_csproj_without_item_group_adds_reference fails on master with the TypeError and passes with the fix; the rest of the library tests still pass.

This PR was prepared with AI assistance (Claude Code) and submitted by the account owner.

The parsed csproj is already the Project root, so find(".//Project")
returned None and SubElement raised. Use the root element directly.

Co-Authored-By: Claude Sonnet 5.5 <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.

Adding the first C# library reference fails when the project has no ItemGroup

1 participant