question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambiguous OpenXmlElement constructors

See original GitHub issue

Description

Greetings. Some time ago we started analyzing our code with SonarQube, and I have noticed a large number of reports in cases like these:

placeholder.InsertBeforeSelf(new Paragraph(new ParagraphProperties(new SpacingBetweenLines() { After = "0" })));

which lead to warnings like this:

S3220: Review this call, which partially matches an overload without ‘params’. The partial match is ‘Paragraph.Paragraph(IEnumerable<DocumentFormat.OpenXml.OpenXmlElement> childElements)’.

This happens because

  • all (most?) OpenXmlElements define two constructors:
    • one accepting an IEnumerable<OpenXmlElement>
    • one accepting an OpenXmlElement[] as params
  • OpenXmlElement implements IEnumerable<OpenXmlElement>

A call with a single OpenXmlElement as the argument is correctly resolved with the params[] overload, so this does not cause actual problems. However, this report shows this usage is king of ambiguous which I agree with (note also OpenXmlElement.Append and Linq.Enumerable.Append).

Information

  • .NET Target: .NET Core (irrelevant)
  • DocumentFormat.OpenXml Version: 2.16.0 (and previous)

Expected

I guess adding an OpenXmlElement(OpenXmlElement) constructor would solve this issue, but I understand this would be an immense undertaking (every single OpenXmlElement would have to include it) which is likely not worth the time for this little gain. Moreover, while I understand and agree with this specific rule, I do not know how SonarQube rules are regarded in general / whether others share this sentiment.

Please consider this as just a comment about something I noticed and not as a strong request.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
twsouthwickcommented, Jun 16, 2022

This could be considered. However, I’m unsure of the value of this. The C# compiler itself doesn’t warn about this and binds to the expected overload. I’d need to be convinced of the value here due to the number of custom types that this would be added to.

0reactions
twsouthwickcommented, Jun 28, 2022

I’m going to close this for now. Please feel free to reopen/comment if there’s an actual blocker here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ambiguous OpenXmlElement constructors · Issue #1136
A call with a single OpenXmlElement as the argument is correctly resolved with the params[] overload, so this does not cause actual problems....
Read more >
java - What does "The constructor ... is ambiguous" mean?
This means that you have two constructors with the same signature, or that you're trying to create a new instance of Case with...
Read more >
DataTable Class (DocumentFormat.OpenXml.Drawing. ...
Constructors ; DataTable(OpenXmlElement[]). Initializes a new instance of the DataTable class with the specified child elements. ; DataTable(String). Initializes ...
Read more >
How to solve ambiguous constructors when trying to start ...
Does anyone have an answer as to how to solve ambiguous constructor issues, like this one above? configuration · exm · Share.
Read more >
Open XML Format SDK forum
Hi! I have created an excel application that can read and write xlsx file using Unity (Client) , Visual Studio (DLL) and openxml...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found