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

Exporting a grid crashes (for me) in latest version 5.0.12 #416

Open
miszelek opened this issue May 30, 2024 · 2 comments
Open

Exporting a grid crashes (for me) in latest version 5.0.12 #416

miszelek opened this issue May 30, 2024 · 2 comments

Comments

@miszelek
Copy link

miszelek commented May 30, 2024

After upgrading to 5.0.12 (from 5.0.11) exporting a grid fails with the following error:

[2024-05-30T13:21:44.621Z] Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)
   at GridBlazor.ExcelCell.RemoveInvalidXmlChars(String content)
   at GridBlazor.ExcelCell.set_Content(String value)
   at GridBlazor.ExcelCell..ctor(String value, Type type)
   at GridBlazor.ExcelWriter.GenerateExcel[T](IGridColumnCollection`1 columns, IEnumerable`1 items)
   at GridBlazor.CGrid`1.DownloadExcel(IJSRuntime js, String filename)
   at GridBlazor.Pages.GridComponent`1.ExcelHandler()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

To Reproduce
I am trying to make a small repro which shows the issue, but did not succeed yet.
But my project has this issue in version 5.0.12, but export works normally in 5.0.11 and below.

Looking into the GridBlazor code changes for 5.0.12 I wonder if the change (RemoveAndInvalidXmlChars) takes into account when the given string is null.
Calling LINQ Where() on a null value also provides an exception.

Expected behavior
Exporting a grid should result in a Excel file (and not an exception).

Possible Fix
Adding a conditional null operator (?) on content variable prevents this.

private string RemoveInvalidXmlChars(string content)
{
  return new string(content?.Where(ch => System.Xml.XmlConvert.IsXmlChar(ch)).ToArray());
}

Desktop:

  • OS: Windows
  • Browser [Chrome]
  • Version [5.0.12]
@gustavnavar
Copy link
Owner

I've published a new package version with your modification

@miszelek
Copy link
Author

miszelek commented Jun 1, 2024

Thanks for the quick fix!
Updated to the new package and Export is working again.

Btw, I love GridBlazor, keep up the good work!

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