How to handle errors in my code
Hi,
whenever an invalid Excel sheet is loaded an error message is shown which offers to reload.
But this does not help if there is something wrong with the loaded file.
Therefore I would like to intercept error handling or at least extend it. But I did not find a way to do so.
Could you help me with that and provide an example how to do Error Handling with the Spreadsheet control in such a case or in general. I can image that there could be cases where it comes to errors during editing. I would also like to handle errors that might be raised during editing.
Kind regards
Frank
Hi Frank,
Thank you for reaching out.
We have reviewed your query regarding scenarios related to loading invalid Excel files and handling errors during editing in the Blazor Spreadsheet. Please find the details below.
Handling invalid Excel files during loading:
These warning dialogs are shown for the following cases:
- Invalid or unsupported file formats: If the loaded file is not in a supported Excel format, the Spreadsheet identifies this and shows a warning message.
- Large Excel files: When the uploaded Excel file exceeds the default file size or data size limit it will throw the alert dialog below to skip the opening of larger size in spreadsheet. By clicking the Cancel button, it will skip the importing progress. If you click OK button, then spreadsheet again tries to load the file.
Error handling during editing operations:
In general, during normal editing operations, the Blazor Spreadsheet does not raise runtime errors. Editing actions such as updating cell values handled smoothly without throwing exceptions.
For formula-related scenarios, the component handles validations as follows:
- Circular reference: If a circular reference is detected in a formula, the Spreadsheet displays a warning dialog to notify the user about the issue. Please refer to the attached image showing the circular reference warning dialog.
- Invalid or improper formula: If a formula is entered incorrectly or contains an unrecognized name, the edited cell will display
#NAME!as the result.
Additionally, for editing, the Spreadsheet provides built-in editing events such as CellEditing and CellSaved. Using the CellEditing event, you can validate the input and cancel the edit operation before the value is saved to the cell. This allows you to prevent invalid data from being committed. The CellSaved event can be used to track successful edits after the value is stored. Please refer the below editing event documentation.
Documentation link: https://help.syncfusion.com/document-processing/excel/spreadsheet/blazor/editing#events
Kindly review the details shared above. Additionally, please provide the following information from your end to help us validate the issue further:
- If you are encountering any other issues while loading an Excel file that do not fall under the scenarios mentioned above, please share the Excel file with us. This will help us analyze the file and assist you more effectively.
- If you are facing any issues while editing a cell, please share the exact issue scenario, along with the steps that lead to the problem.
- If possible, please share an Excel file that reproduces the issue during editing.
Please share the above requested details from your end. Based on that, we will validate and update you with further details.
Please feel free to reach out to us if you have any further questions or concerns.
Regards,
Adithyan.
Dear
Adithyan,
so there is no chance to implement my own error handling style, with my own error dialogs with information I want to provide for the users. That is a pity. Are these error messages available in all languages or how can I set a translation?
And you did not cover the scenario in which the error is not shown in a message box but as part of the web site. I have added a hardcopy of the szenario.
I assume the folder or file is write protected but I am not sure because I do not see any error message. All I can say it happens when the spreadsheet first loads the data.
Kind regards
Frank
Dear
Adithyan,
so there is no chance to implement my own error handling style, with my own error dialogs with information I want to provide for the users. That is a pity. Are these error messages available in all languages or how can I set a translation?
And you did not cover the scenario in which the error is not shown in a message box but as part of the web site. I have added a hardcopy of the szenario.
I assume the folder or file is write protected but I am not sure because I do not see any error message. All I can say it happens when the spreadsheet first loads the data.
Kind regards
Frank
Hi Frank,
Thank you for reaching out to us.
We have reviewed the details you shared regarding the customization of validation dialog messages and the error behavior observed while loading data in the Syncfusion Blazor Spreadsheet. Please find our detailed responses to each query below.
1.Customizing validation dialog content and localization support
We understand that your requirement is to display your own messages for the Spreadsheet’s built‑in alert dialogs. The Syncfusion Blazor Spreadsheet component fully supports such customization using our localization mechanism, where dialog text can be overridden through localization keys.
Please note that localization content must be defined individually for each culture. Updates made for one culture will not automatically apply to others.
As an example, we customized the Circular Reference dialog message for the en-US culture (see attached screenshot).
You can update dialog content for other supported cultures by adding the corresponding .resx files to your application’s Resources folder. The full list of supported localization languages is available in the Syncfusion Blazor localization repository:
Repository link: https://github.com/syncfusion/blazor-locale
You can customize additional validation dialogs using the following localization keys:
- Spreadsheet_UnsupportedFile
- Spreadsheet_FileLimitExceed
- Spreadsheet_DataLimitExceed
- Spreadsheet_CircularReference
By setting the localization values for each culture, you can completely customize the dialog content for all supported languages. Below is a sample configuration demonstrating how localization is enabled in the application:
//Add services to the container builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddSyncfusionBlazor(); builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); var app = builder.Build(); // Configure localization (update culture as needed) app.UseRequestLocalization("en-US"); |
For more information regarding the localization, please refer to the this documentation: https://blazor.syncfusion.com/documentation/common/localization
You may switch to any other culture as required to load the corresponding localized resources. For your convenience, we have prepared a sample application with the above configurations and included it with our response for the second query.
2. Error shown on the web page while loading data
We have validated the reported issue regarding the error occurs while the data into the Spreadsheet based on the shared details. To test this scenario, we have loaded a Spreadsheet with the sample excel file and the Spreadsheet loaded properly with the data without any issues on our end. And we haven’t faced any issues while loading. Please refer to the attached screenshot and sample project that we have test.
Sample application: Please refer to the attachment.
Additionally, we suspect that the issue that you reported may be related to some other customization in application end and not solely within the Spreadsheet. To further validate the reported behaviour, we kindly request you to share the following details:
- If the reported issue occurs only with a specific file, please share that file with us (with dummy data) to validate the issue.
- If any script errors are logged in the browser console, please share those details along with a screenshot.
- Additionally, if you have applied any customizations on your end, please provide those details as well.
- Please confirm whether you are facing the issue with any specific culture, if so, please share those details.
- If possible, please try to replicate the reported issue using the shared sample project and send it back to us for further validation.
Sharing the above requested details from your end will allow us to validate and update you with appropriate details.
Please let us know if you have any additional questions or concerns.
Regards,
Prakash Raj Kumar
Attachment: BlazorSpreadsheet_d0dd10ff.zip
Hi,
the explanation for localization is very good. Thank you for that.
I found out in which case I get the error of which I put a hardcopy in my last reply.
If you try to open the file I attached you will get the respective error message. As you notice this is an empty file.
It would be good if you could cathc the empty file error. But all in all I am fine with your answers.
Thank you very ymuch
Frank
Hi Frank,
Thank you for your update.
We’re glad to hear that the explanation regarding localization was helpful.
We would like to clarify that in your previous reply, only the error image was attached. We did not find any hardcopy (sample file or project) in either your current or previous updates. However, as you mentioned earlier that the file might be protected, we attempted to validate this scenario on our side by loading both a password‑encrypted file and an empty file.
During our testing, we loaded the password‑encrypted and empty files in a project with localization enabled for different cultures. The validation dialog appeared as expected, and after entering the correct password, the file loaded successfully in our Spreadsheet component.
For your reference, we have prepared a short video demonstrating this behavior and attached it below along with the tested file.
Encrypted File: Please refer to the attachment (Password: Hello)
Since we were unable to fully reproduce the exact behavior you are encountering, we kindly request that you share the sample file you are trying to load or a minimal project that reproduces the issue. This will help us analyze the problem more precisely and provide an appropriate solution as quick as possible.
Attachment: EncryptedFile_Hello_9c1ca756.xlsx
Hi,
I attached the file that leads to this message. It is somehow corrupt because it has the size 0
A sample is included in the attached Zip
Kind regards
Frank
Attachment: Mien.Tztzrtzest_428933e1.zip
Hi,
I attached the file that leads to this message. It is somehow corrupt because it has the size 0
A sample is included in the attached Zip
Kind regards
Frank
Hi Frank,
Thank you for sharing the file with us.
We have validated the reported issue by opening the Excel file you provided and were able to reproduce the reproduce exception while loading into our Spreadsheet. During our investigation, we observed that the file has a size of 0 KB and is corrupted, which results in a ZIP-related exception when attempting to load it into the Blazor Spreadsheet component.
Disclaimer: “Inclusion of this solution in the release may change due to other factors including but not limited to QA checks and works re prioritization”.
Based on our analysis, we will handle the file‑loading error as described below:
- When a ZIP‑related exception occurs (for example, when loading a corrupted or zero‑byte file), the Spreadsheet component will display a warning dialog indicating that the file is unsupported.
- For other types of exceptions, the Spreadsheet will display a warning dialog with the exact exception details, allowing users to view the cause of the issue.
With these improvements, the Spreadsheet component will no longer crash if a file fails to load. Instead, it will show the appropriate warning message and continue functioning with the currently loaded Spreadsheet.
Please review the above shared details and let us know if you have any further questions or concerns.
Regards,
Adithyan
We are glad to announce that our weekly patch release (33.1.46) is rolled out and we have included the fix for the reported "Exception occurs when loading corrupted or unsupported Excel file in Blazor Spreadsheet" issue in this release. So, kindly upgrade your package version to the latest to avail of these changes (33.1.46).
Package Link: NuGet Gallery | Syncfusion.Blazor.Spreadsheet 33.1.46
For your reference, we have attached the video demonstration with the latest Nuget.
Video demonstration:
Issue Root Cause:
During Excel file loading, ZIP‑related and file‑corruption scenarios were not adequately handled, which could result in unhandled exceptions when attempting to load corrupted or invalid files. This has been addressed by adding proper exception handling for ZIP and file‑corruption cases, where the Spreadsheet now displays an “unsupported file” warning dialog. In addition, general exceptions that occur during file loading are also captured and shown in a warning dialog with detailed error information, helping users easily identify the cause of the issue.
Please review the above shared details and feel free to reach out to us if you have any further questions or concerns.
Regards,
Adithyan
Hi,
unfortunately I still the same behavior.
The Spreadsheet version is updated.
In your example you used the UI to open the file but I am using this code in this code in the Blazor component to open the file. The content is sent as part of a message.
private void OnOpenExcelFileMessage(object recipient, OpenExcelFileMessage Message) { Debug.WriteLine("Razor: OpenExcelFileMessage received"); DataSourceBytes = Message.ExcelFileContent; Debug.WriteLine($"Razor {DataSourceBytes.Length}"); _spreadsheetKey++; // Change key to force component recreation StateHasChanged(); WeakReferenceMessenger.Default.Send(new BusyMessage(this, false)); }
In the MAUI part of the app I am using this code (shortened). The FilePicker is a component from the .net maui
Microsoft.Maui.Storage
varcustomFileType = newFilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>> { { DevicePlatform.Android, new[] { "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } }, // MIME type { DevicePlatform.WinUI, new[] { ".xlsx", ".xls"} }, // file extension });
PickOptions options = new() { PickerTitle = AppResource.MainPageOpenWorkbookTitle, FileTypes = customFileType, }; var result = await FilePicker.Default.PickAsync(options); if (result != null) { if (result.FileName.EndsWith("xlsx", StringComparison.OrdinalIgnoreCase)) { using (var memoryStream = new MemoryStream()) { var fs = await result.OpenReadAsync(); fs.CopyTo(memoryStream); fs.Close(); var data = memoryStream.ToArray(); WeakReferenceMessenger.Default.Send(new OpenExcelFileMessage(this, data));
}
}
}
Could you please double check the solution if the file is loaded like I did.
Kind regards
Frank
Attachment: S4E20260331_9b78c093.zip
Hi,
unfortunately I still the same behavior.
The Spreadsheet version is updated.
In your example you used the UI to open the file but I am using this code in this code in the Blazor component to open the file. The content is sent as part of a message.
private void OnOpenExcelFileMessage(object recipient, OpenExcelFileMessage Message) { Debug.WriteLine("Razor: OpenExcelFileMessage received"); DataSourceBytes = Message.ExcelFileContent; Debug.WriteLine($"Razor {DataSourceBytes.Length}"); _spreadsheetKey++; // Change key to force component recreation StateHasChanged(); WeakReferenceMessenger.Default.Send(new BusyMessage(this, false)); }
In the MAUI part of the app I am using this code (shortened). The FilePicker is a component from the .net maui
Microsoft.Maui.Storage
varcustomFileType = newFilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>> { { DevicePlatform.Android, new[] { "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } }, // MIME type { DevicePlatform.WinUI, new[] { ".xlsx", ".xls"} }, // file extension });
PickOptions options = new() { PickerTitle = AppResource.MainPageOpenWorkbookTitle, FileTypes = customFileType, }; var result = await FilePicker.Default.PickAsync(options); if (result != null) { if (result.FileName.EndsWith("xlsx", StringComparison.OrdinalIgnoreCase)) { using (var memoryStream = new MemoryStream()) { var fs = await result.OpenReadAsync(); fs.CopyTo(memoryStream); fs.Close(); var data = memoryStream.ToArray(); WeakReferenceMessenger.Default.Send(new OpenExcelFileMessage(this, data));
}
}
}
Could you please double check the solution if the file is loaded like I did.
Kind regards
Frank
Hi Frank,
Thank you for the detailed follow‑up.
We have validated the shared details and would like to clarify the following. In our previous update, we validated and handled file‑loading exceptions only when the Excel file was opened via Ribbon UI option within the Spreadsheet. However, we missed validating the scenario where the DataSourceBytes property is updated dynamically. We sincerely apologize for this oversight and for the inconvenience it may have caused.
Based on the information you provided, we were able to reproduce the issue with the following flow:
· Passing a corrupted or zero‑byte Excel file
· Dynamically assigning it to DataSourceBytes
· Forcing component re‑creation using _spreadsheetKey++
In this scenario, the Spreadsheet continues to throw an unhandled exception instead of displaying the Unsupported File dialog, which matches the behavior observed in your environment.
As a result, we have considered this behavior as a defect and logged a bug report titled: "Unhandled Exception When Dynamically Updating Blazor Spreadsheet Data Source with Corrupted or Zero‑Byte Excel Files". The fix for this issue will be available in our third weekly release of April 2026. We appreciate your patience until then. You can track the status of the issue via the feedback link below.
Feedback link: https://www.syncfusion.com/feedback/73506/unhandled-exception-when-dynamically-updating-blazor-spreadsheet-data-source-with
Disclaimer: “Inclusion of this solution in the release may change due to other factors including but not limited to QA checks and works re prioritization”.
As a temporary solution, you can prevent the exception by pre‑validating the Excel file bytes before assigning them to the Spreadsheet. For your convenience, we have prepared a sample where we added a button named “Load Sheet”. When this button is clicked, the file is first validated by attempting to open it using the Syncfusion XlsIO library within a try‑catch block before setting the DataSourceBytes.
If any exception occurs, an alert is displayed with the exception message, and DataSourceBytes is not assigned. If no exception occurs, the DataSourceBytes property is assigned, and the Spreadsheet is re‑rendered.
With this approach:
· Corrupted or unsupported files are safely intercepted
· The application does not crash
· Users receive a meaningful error message
Below, we have shared the relevant code snippets along with the prepared sample and a video demonstration for reference.
Code snippets:
public async Task LoadSheet() { string filePath = "wwwroot/Mien.Tztzrtzest.xlsx"; try { // Read the file bytes byte[] fileBytes = File.ReadAllBytes(filePath); // Validate if it's a valid Excel file stream if (IsValidExcelFile(fileBytes, out string errorMessage)) { DataSourceBytes = fileBytes; spreadsheetKey++; // Change key to force component recreation StateHasChanged(); } else { // Show alert with the exception message using JS Interop await JSRuntime.InvokeVoidAsync("alert", $"Invalid Excel file: {errorMessage}"); } } catch (Exception ex) { await JSRuntime.InvokeVoidAsync("alert", $"Error loading file: {ex.Message}"); } } |
Sample: Please refer to the attachment.
Video demonstration:
Kindly use this workaround until the fix is officially released. We will keep you informed once the issue is resolved and the updated version becomes available.
Please feel free to reach out if you have any further questions or concerns.
Best Regards,
Prakash Raj Kumar.
Attachment: SfSpreadsheet_c74efed.zip
Hi Frank,
We are glad to announce that our Essential Studio® 2026 Volume 1 Service Pack 1 (SP) Release v33.2.3 is rolled out and is available for download under the following link.
Essential Studio® 2026 Volume 1... | Announcements Forums | Syncfusion
We have included the fix for the issue "Unhandled Exception When Dynamically Updating Blazor Spreadsheet Data Source with Corrupted or Zero‑Byte Excel" in this release. We recommend updating to the latest version (v33.2.3) to obtain the fix.
For your convenience, we have prepared a sample with latest package and attached below along with the video demonstration for reference
Sample: Please refer to the attachment.
Video demonstration: