question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.ArgumentException occurs while sorting the column when column name contains a comma(,) in DataTable collection

See original GitHub issue

This issue has been moved from a ticket on Developer Community.


I have defined the column name with a comma(,) in the DataTable collection. In this case, while sorting the column in DataGrid System.ArgumentException occurs. Replication procedure to reproduce the reported issue,

Step 1: set the column name property as below mentioned

//I have defined the column name with a comma
EmployeeDetails.Columns.Add("Cell (Row,Col)", typeof(string)); 

Please refer to the screenshot, ! [ColumnName.png] (https://aka.ms/dc/image?name=Be08250778a8444eaac4396a6d96439d6637549653017445778_ColumnName.png&tid=e08250778a8444eaac4396a6d96439d6637549653017445778)

Step 2: Run the sample

Step 4: Sort the Cell (Row,Col) column in DataGrid

Step 5: System.ArgumentException occurs

StackTrace details for your reference,

System.ArgumentException HResult=0x80070057 Message=[Cell (Row isn’t a valid Sort string entry. Source=System.Data StackTrace: at System.Data.DataTable.ParseSortString(String sortString) at System.Data.DataView.CheckSort(String sort) at System.Data.DataView.set_Sort(String value) at System.Data.DataView.System.ComponentModel.IBindingListView.ApplySort(ListSortDescriptionCollection sorts) at System.Windows.Data.BindingListCollectionView.<>c__DisplayClass96_0. b__1() at MS. Internal.Data.SynchronizationInfo.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess) at System.Windows.Data.BindingOperations.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess) at System.Windows.Data.BindingListCollectionView.RefreshOverride() at System.Windows.Data.CollectionView.RefreshInternal() at System.Windows.Data.CollectionView.Refresh() at System.Windows.Data.CollectionView.EndDefer() at System.Windows.Data.CollectionView.DeferHelper.Dispose() at System.Windows.Controls.ItemCollection.EndDefer() at System.Windows.Controls.ItemCollection.DeferHelper.Dispose() at System.Windows.Controls.DataGrid.DefaultSort(DataGridColumn column, Boolean clearExistingSortDescriptions) at System.Windows.Controls.DataGrid.OnSorting(DataGridSortingEventArgs eventArgs) at System.Windows.Controls.DataGrid.PerformSort(DataGridColumn sortColumn) at System.Windows.Controls.Primitives.DataGridColumnHeader.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Primitives.DataGridColumnHeader.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS. Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS. Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS. Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS. Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at SortingString.App.Main()

This exception was originally thrown at this call stack: [External Code]

I have attached the sample for your reference

Sample Link : SortingString.zip

Can anyone share an idea to resolve the reported problem?

Regards, Vijayarasan S


Original Comments

Feedback Bot on 4/27/2021, 10:32 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Vijayarasan Sivanandham on 6/2/2021, 02:24 PM:

Hi Team,

Any update on this.

Regards,
Vijayarasan S

Feedback Bot on 8/2/2021, 03:27 PM:

I detected that this issue hasn’t received a lot of activity, votes, or comments in the past 90 days. Based on this, the issues severity and affected area, it’s my experience that this issue is unlikely to get fixed. To improve the situation, consider following best practices for quality problem reports, and giving us more details on how this issue is impacting you.

Mila Zhou[MSFT] on 1/21/2022, 05:56 PM:

Thank you for taking the time to log this issue! Did you still reproduce this issue in the latest stable version of Visual Studio installed from https://visualstudio.microsoft.com/downloads ?

Vijayarasan Sivanandham on 2/9/2022, 04:27 PM:

Hi Team,

I have tested with the latest Visual Studio 2022. The reported problem still occurs. Please find the Visual Studio version details in the below mentioned screen shot,

VisualStudioVersion.png

Regards,
Vijayarasan S

Feedback Bot on 2/9/2022, 03:23 PM:

We will close this report in 14 days because we don’t have enough information to investigate further. To keep the problem open, please provide the requested details.

Vijayarasan Sivanandham on 2/9/2022, 04:32 PM:

Hi Team,

Please check the reported problem in the Visual studio 2022 version.

Regards,
Vijayarasan S

Feedback Bot on 2/11/2022, 01:41 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 2/14/2022, 05:53 PM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
miloushcommented, Apr 25, 2023

@anjali-wpf Please note that in the repro, user clicks on a DataGrid column header, there is no code invovled. If the column name needs to be wrapped in square brackets, it is DataGrid’s responsibility to do so. Second, the code you suggested does not actually work, it throws an exception, because DataView/DataTable does not have this escaping implemented.

I filed https://github.com/dotnet/runtime/issues/85365 and https://github.com/dotnet/runtime/issues/85367 to address that.

I think this issue can be closed as external, but #6145 will need to be addressed by WPF somehow to support brackets and dots inside the names.

1reaction
miloushcommented, Apr 25, 2023

Related to #6145 (SortMember is prefilled from binding’s path in DataGridBoundColumn.OnCoerceSortMemberPath), but a separate set of issues.

The code responsible for translating WPF binding into .NET binding is DataView.CreateSortString. According to the Expression Syntax it is unsatisfactory in the sense that it does not escape the ] and \ characters in property names. ~This should be fixed on WPF side.~ (EDIT: this is System.Data assembly) It also appears to me that SortMember should either accept the same path escaping as binding paths, or it should unescape the path when copying the member name from a binding.

However, there is another bug on the .NET side which is that contrary to the documentation (see Remarks for DataTable.Select and expression syntax above), the DataTable.ParseSortString:

  1. completely inappropriately splits the string by comma first
  2. does not unencode column names enclosed by [ ]
  3. does not support column names enclosed by `

The repro would work if 1. is fixed in the DataTable class, which is not part of WPF.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - DataTable sorting with Datacolumn Name with comma
I have applied some logic and it gives me column name to sort the respective column name and bind the data again with...
Read more >
Search existing .NET feedback
System.ArgumentException occurs while sorting the column when column name contains a comma(,) in DataTable collectionClosed - Duplicate1 9.
Read more >
Disable sorting of one column
I am using dataTables 1.10 in server-side mode with Scroller. I tried to disable sorting in my first column by setting "orderable" to...
Read more >
Error when sorting columns with spaces in SortExpression
When I sort by this column I am getting the following error: [Dynamic Column Name] is neither a DataColumn nor a DataRelation for...
Read more >
DataView.Sort Property (System.Data)
Gets or sets the sort column or columns, and sort order for the DataView. ... A string that contains the column name followed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found