Skip to content

Commit 7d7ed1b

Browse files
dimodijivanova
authored andcommitted
docs(fileselect): Add KB for sync Stream exceptions
1 parent 502047f commit 7d7ed1b

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed

components/fileselect/events.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ Property | Type | Description
3333
`InvalidExtension` | `bool` | a boolean flag that shows if the file type is invalid
3434
`InvalidMinFileSize` | `bool` | a boolean flag that shows if file size is below the minimum
3535
`InvalidMaxFileSize` | `bool` | a boolean flag that shows if the file size exceeds the maximum
36-
`Stream`| `FileInfoStream` | a [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream) that can be used to load the file to memory, file system or other. Use it to asynchronously get the file contents as byte array.
36+
`Stream`| `FileInfoStream` | a [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream) that can be used to load the file to memory, file system or other. Use it to **asynchronously** get the file contents as byte array.
3737

38+
> Due to Blazor framework limitations, `FileInfoStream` does not support **synchronous** operations such as `Read`, `Seek`, `Flush` and `Write`. The methods exist, but will [throw an exception]({%slug fileselect-kb-stream-exception%}). A possible workaround is to copy the `FileInfoStream` **asynchronously** to another `Stream` via `CopyToAsync`. The `OnSelect` event example below demonstrates this.
3839
3940
## OnSelect
4041

@@ -73,10 +74,10 @@ The event handler receives a [`FileSelectEventArgs` object](#fileselectfileinfo)
7374
{
7475
if (!file.InvalidExtension)
7576
{
76-
// save to local file system
77+
// save to local file system
7778
await UploadFile(file);
78-
// or read file in-memory
79-
//await ReadFile(file);
79+
// or read file in-memory
80+
//await ReadFile(file);
8081
}
8182
}
8283
}
@@ -99,8 +100,6 @@ The event handler receives a [`FileSelectEventArgs` object](#fileselectfileinfo)
99100
}
100101
````
101102

102-
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
103-
104103

105104
## OnRemove
106105

knowledge-base/common-null-value-parameter-format.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ I am getting an error when I am using a Telerik Blazor component in an applicati
3030
The exact error message can vary. Here are just a few examples:
3131

3232
>warning Unhandled exception rendering component: Value cannot be null. (Parameter 'format')
33+
>
3334
System.ArgumentNullException: Value cannot be null. (Parameter 'format')
35+
>
3436
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
37+
>
3538
at System.String.Format(String format, Object arg0, Object arg1)
39+
>
3640
at Telerik.Blazor.Components.TelerikWizard.get_PagerMessage()
3741

3842
>warning System.ArgumentNullException: Value cannot be null. (Parameter 'format')
43+
>
3944
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
45+
>
4046
at Telerik.Blazor.Components.Common.Filters.FilterMenu.TelerikFilterMenu.get_FilterMenuSettingsLabel()
4147

4248

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: FileSelect Stream throws NotImplementedException
3+
description: FileSelect Stream (FileInfoStream) methods throw Not Implemented exceptions
4+
type: troubleshooting
5+
page_title: FileSelect Stream throws NotImplementedException
6+
slug: fileselect-kb-stream-exception
7+
position:
8+
tags: fileselect, exception
9+
ticketid: 1551288, 1552410, 1560275, 1585580
10+
res_type: kb
11+
---
12+
13+
## Environment
14+
15+
<table>
16+
<tbody>
17+
<tr>
18+
<td>Product</td>
19+
<td>FileSelect for Blazor</td>
20+
</tr>
21+
</tbody>
22+
</table>
23+
24+
25+
## Description
26+
27+
The `file.Stream` object in the [FileSelect `OnSelect` event handler]({%slug fileselect-events%}#onselect) throws a `NotImplementedException`.
28+
29+
The FileSelect `Stream` (`FileInfoStream`) has exposed methods that are "not implemented".
30+
31+
## Error Message
32+
33+
>warning System.NotImplementedException: The method or operation is not implemented.
34+
>
35+
at Telerik.Blazor.Components.FileSelect.Stream.FileInfoStream.Read()
36+
37+
The same exception will occur for the following methods and properties:
38+
39+
* `Position`
40+
* `Flush()`
41+
* `Read()`
42+
* `Seek()`
43+
* `SetLength()`
44+
* `Write()`
45+
46+
## Cause\Possible Cause(s)
47+
48+
Due to Blazor framework limitations, [`FileInfoStream` does not support synchronous operations]({%slug fileselect-events%}#fileselectfileinfo) such as `Read`, `Seek`, `Flush` and `Write`. The methods exist, but throw an exception.
49+
50+
## Solution
51+
52+
Copy the `FileInfoStream` **asynchronously** to another `Stream` via `CopyToAsync()`. Apart from the example below, also check the [FileSelect `OnSelect` event documentation]({%slug fileselect-events%}#onselect).
53+
54+
>caption Copy the FileSelect Stream to another one and use sync methods
55+
56+
```CSHTML
57+
@using System.IO
58+
59+
<TelerikFileSelect OnSelect="@ReadSelectedFiles" />
60+
61+
@code {
62+
private async Task ReadSelectedFiles(FileSelectEventArgs args)
63+
{
64+
foreach (var file in args.Files)
65+
{
66+
var ms = new MemoryStream();
67+
await file.Stream.CopyToAsync(ms);
68+
69+
var byteArray = new byte[file.Size];
70+
71+
ms.Seek(0, SeekOrigin.Begin); // not supported by file.Stream
72+
ms.Read(byteArray); // not supported by file.Stream
73+
}
74+
}
75+
}
76+
````
77+
78+
## See Also
79+
80+
* [FileSelect Overview]({%slug fileselect-overview%})

0 commit comments

Comments
 (0)