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

After updating to VS 17.6 this error started. #1

Open
mikeacu opened this issue Jun 23, 2023 · 8 comments
Open

After updating to VS 17.6 this error started. #1

mikeacu opened this issue Jun 23, 2023 · 8 comments

Comments

@mikeacu
Copy link

mikeacu commented Jun 23, 2023

System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at MsBuildToCCNetvNext.Utilities.SanitizeMessageForXml(String input)
at MsBuildToCCNetvNext.Message.get_XmlFragement()
at MsBuildToCCNetvNext.Project.get_XmlFragment()
at MsBuildToCCNetvNext.MsBuildToCCNetvNext.Shutdown()
at Microsoft.Build.BackEnd.Logging.LoggingService.ShutdownLogger(ILogger logger)

It was determined that msbuild is now sometimes posting null messages.

@aolszowka
Copy link
Owner

Great to hear again from you Mike; I'd be happy to take a PR that resolves the issue.

I'd probably suggest adding a check like this:

        internal static string SanitizeMessageForXml(string input)
        {
            string sanitizedMsg = input;
            if(string.IsNullOrEmpty(sanitizedMsg)) {
                sanitizedMsg = string.Empty;
            }
            else if (MessageNeedsSanitation(input))
            {
                string invalidXmlCharactersRemoved =
                            new string(input.AsEnumerable().Where(currentChar => XmlConvert.IsXmlChar(currentChar)).ToArray());
                sanitizedMsg =
                    string.Format("WARNING This message contained invalid XML character(s) which have been removed: {0}", invalidXmlCharactersRemoved);
            }

            return sanitizedMsg;
        }

This should still just build with lock-stock-standard Visual Studio

@mikeacu
Copy link
Author

mikeacu commented Jun 23, 2023 via email

@aolszowka
Copy link
Owner

I think it comes down to what you want the behavior of the logger to be in that scenario; I believe with your code above it will throw and still die in the logger right? If you're seeing null messages you probably either want to just log a blank and continue on, or even just squelch the message.

Did you have a particular path in mind?

@mikeacu
Copy link
Author

mikeacu commented Jun 23, 2023

Preferably I think we just want to squelch the nulls as they have no value in the logs. As a quick workaround I just changed CC to use the default mslogger. Its not pretty but it got us back working.

@aolszowka
Copy link
Owner

IIRC the reason we are using the custom logger is for the XLT Transform to work on the build output (you're probably going to be missing Errors, Warnings, and Info Messages). If you've moved away from that no big deal, but if you're still using it the default logger doesn't work. Its also even worse when building in Parallel.

If you want to just squelch the null messages you'll need to change this section:

https://github.com/aolszowka/MsBuildToCCNetvNext/blob/5dab036a03d755eaac9d4bd1241238bad3786cec/MsBuildToCCNetvNext/MsBuildToCCNetvNext.cs#L257C9-L281C10

To do something like (obviously repeated for each of those sections and with the correct type):

if(String.IsNull(e.Message)) {
    // Do nothing
}
else {
    Project currentProject = this.GetOrCreateAssociatedProject(e.ProjectFile);
    currentProject.Add(new Error(e));
}

@mikeacu
Copy link
Author

mikeacu commented Jun 23, 2023

Yeah I know we are missing data in the logs. Luckily we had only updated one of the CC builds with VS 17.6 when we discovered the issue. I'll give that a try and post a pr later today. Thanks.

@mikeacu
Copy link
Author

mikeacu commented Jun 27, 2023

Ace that last suggestion worked great. I was unable to create a remote branch and subsequent PR.

remote: Permission to aolszowka/MsBuildToCCNetvNext.git denied to mikeacu.

@aolszowka
Copy link
Owner

@mikeacu Its because you are attempting to edit my Git Repository, to contribute on GitHub you need to hit Fork make the changes in your version of the project and then submit a PR upstream. This walks you through it pretty well: https://docs.github.com/en/get-started/quickstart/contributing-to-projects

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

No branches or pull requests

2 participants