XamlStyler icon indicating copy to clipboard operation
XamlStyler copied to clipboard

Extra space in WPF Setter Property value throwing exception while formatting

Open chuongmep opened this issue 2 years ago • 5 comments

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):

  • OS: [e.g. Windows 10 (1903), MacOS (10.15) , Ubuntu (19.10), etc.]
  • Visual Studio: VS 2022 Preview
  • XAML Styler: [e.g., Extension (3.2001.0), Console (3.1912.0), etc.]

Additional context Add any other context about the problem here.

chuongmep avatar Feb 25 '22 16:02 chuongmep

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

RedX2501 avatar Mar 09 '22 08:03 RedX2501

@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?

grochocki avatar Mar 09 '22 09:03 grochocki

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

chuongmep avatar Mar 09 '22 09:03 chuongmep

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".

RedX2501 avatar Mar 09 '22 09:03 RedX2501

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

grochocki avatar Mar 09 '22 10:03 grochocki