Xavalon / XamlStyler

Visual Studio extension to help format your XAML source code
Apache License 2.0
1.18k stars 128 forks source link

Extra space in WPF Setter Property value throwing exception while formatting #371

Open chuongmep opened 2 years ago

chuongmep commented 2 years ago

Describe the bug The ' ' character, hexadecimal value 0x20, cannot be included in a name.

To Reproduce Steps to reproduce the behavior:

  1. Problem when i try format here https://github.com/chuongmep/Dynamo/blob/master/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
  2. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

External Configuration If you are using an external configuration, please attach to help reproduce the issue.

Version Info (please complete the following information):

Additional context Add any other context about the problem here.

RedX2501 commented 2 years ago

I have a similar message but not the same:

---------------------------
Microsoft Visual Studio
---------------------------
Error in StylerPackage:

Name cannot begin with the ',' character, hexadecimal value 0x2C. Line 153, position 96.

If this deems a malfunctioning of styler, please kindly submit an issue at https://github.com/Xavalon/XamlStyler.
---------------------------
OK   
---------------------------

VS 2022 Version 17.1.0

grochocki commented 2 years ago

@chuongmep I've identified the condition for your repro, but not the root cause. The extra space in Property="Visibility " in this portion of the code is throwing an exception. Removing that extra space should work as a short term mitigation.

image

@RedX2501 Any chance you are encountering a similar issue in your code? If not, can you file a new issue with a representative XAML snippet that reproduces the error you are seeing?

chuongmep commented 2 years ago

whether we can improve it to can work with The extra space ?

RedX2501 commented 2 years ago

I just found out that the root cause is actually the parsing of the XAML file being styled.

I indeed had an extra , in the element which caused the parsing to fail.

I think this is a case where improving the message to say that the error is coming from the file being styled would help greatly.

My bad line was:

                <DataGridTextColumn Binding="{Binding Severity, Mode=OneWay}" Header="Severity", IsReadOnly="True">

notice the , after "Severity".

grochocki commented 2 years ago

whether we can improve it to can work with The extra space ?

I believe this can be addressed. An exception is being thrown in FormatThicknessService if you want to take a look, but I was having trouble loading symbols, so I will need to take a close look another day.

I think this is a case where improving the message to say that the error is coming from the file being styled would help greatly.

I agree -- this is a possible candidate for surfacing in some sort of error/warning UI in the future as part of #271