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

New String.TrimEnd overload breaks MSBuild CoerceArguments on netcoreapp2.0 #1634

Closed
eerhardt opened this issue Jan 31, 2017 · 0 comments
Closed
Labels

Comments

@eerhardt
Copy link
Member

CoreFX has added a new String.TrimEnd overload with dotnet/corefx#15334.

This is breaking MSBuild running on netcoreapp2.0 when building a project that contains logic like the following taken from dotnet/sdk:

<_ShortFrameworkIdentifier>$(TargetFramework.TrimEnd('.0123456789'))</_ShortFrameworkIdentifier>

I get the following error:

Microsoft.NET.TargetFrameworkInference.targets(51,4): error MSB4184: The expression ""netcoreapp2.0".TrimEnd(.0123456789)" cannot be evaluated. String must be exactly one character long. 

I've debugged the error down to this logic in MSBuild:

                        else
                        {
                            // change the type of the final unescaped string into the destination
                            coercedArguments[n] = Convert.ChangeType(args[n], parameters[n].ParameterType, CultureInfo.InvariantCulture);
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    // The coercion failed therefore we return null
                    return null;

The issue is Convert.ChangeType is throwing a FormatException, just like it is documented to do. But this code only catches InvalidCastException. Instead, since trying to convert a string to a single char fails, this method overload should be skipped and keep searching until it finds the overload that accepts char[].

This is blocking the CLI "2.0" work from taking new builds of the .NET Core runtime.

eerhardt added a commit to eerhardt/msbuild that referenced this issue Jan 31, 2017
String.TrimEnd has a new overload for a single char in .NET Core 2.0. However, when MSBuild encounters this new overload first, it throws a FormatException which is not caught - breaking the build.

The fix is to catch the FormatException just like an InvalidCastException and continue searching the rest of the reflection MethodInfos for a match.

Fix dotnet#1634
rainersigwald pushed a commit that referenced this issue Feb 1, 2017
String.TrimEnd has a new overload for a single char in .NET Core 2.0. However, when MSBuild encounters this new overload first, it throws a FormatException which is not caught - breaking the build.

The fix is to catch the FormatException just like an InvalidCastException and continue searching the rest of the reflection MethodInfos for a match.

Fix #1634
eerhardt added a commit to dotnet/cli that referenced this issue Feb 1, 2017
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants