Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullRef on Fact when Value is null #92

Open
riezebosch opened this issue Jan 17, 2025 · 0 comments · May be fixed by #91
Open

NullRef on Fact when Value is null #92

riezebosch opened this issue Jan 17, 2025 · 0 comments · May be fixed by #91

Comments

@riezebosch
Copy link

For our use case, we add ~186 facts to the report. Sometimes the value is null, and the receiving party does not allow empty facts. So instead of adding 102 if-statements surrounding the AddFact methods we just cleanup the report afterwards.

We cannot just loop all facts and remove where Value is null, because the Remove method on the FactCollection will fail with a NullReferenceException. Because the base type collection relies on the GetHashCode and Equals methods of the Fact class, which both assume Value is never null.

https://github.com/dgm9704/Xoxo/blob/main/Diwen.Xbrl/Xml/Fact.cs#L207
https://github.com/dgm9704/Xoxo/blob/main/Diwen.Xbrl/Xml/Fact.cs#L215

Our solution is now to remove by index, but I felt like fixing this underlying issue would be the better approach:

        for (int i = report.Facts.Count - 1; i >= 0; i--)
        {
            if (string.IsNullOrEmpty(report.Facts[i].Value))
            {
                report.Facts.RemoveAt(i); // cannot use Remove(fact) here because of `NullReferenceException`
            }
        }
@riezebosch riezebosch linked a pull request Jan 17, 2025 that will close this issue
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 a pull request may close this issue.

1 participant