-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
ArrayList.ToArray(type) throws exception for enum type in Blazor WebAssembly #64387
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsIs there an existing issue for this?
Describe the bugCode snippet: ArrayList list = new ArrayList(); public enum Day { Monday, Tuesday } This is working fine in .net 6 desktop. But in Blazor WebAssembly, it throws exception System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type. list.ToArray() without type is fine. But we are using type which is loaded in runtime, so the type is required. Expected BehaviorArray created without exception Steps To Reproducehttps://github.com/jjzhang12/WasmToArrayIssue.git I added above code snippet to index page and you can observe the exception. Also the .net console app is working fine. Exceptions (if any)System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type. .NET Version6.0.101 Anything else?No response
|
Tagging subscribers to this area: @BrzVlad Issue DetailsIs there an existing issue for this?
Describe the bugCode snippet: ArrayList list = new ArrayList(); public enum Day { Monday, Tuesday } This is working fine in .net 6 desktop. But in Blazor WebAssembly, it throws exception System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type. list.ToArray() without type is fine. But we are using type which is loaded in runtime, so the type is required. Expected BehaviorArray created without exception Steps To Reproducehttps://github.com/jjzhang12/WasmToArrayIssue.git I added above code snippet to index page and you can observe the exception. Also the .net console app is working fine. Exceptions (if any)System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type. .NET Version6.0.101 Anything else?No response
|
cc @vargaz |
|
It's hitting this check added by mono/mono#15585 runtime/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs Lines 202 to 203 in 9eb9051
which doesn't look right to me (it's comparing Repro with: var list = new System.Collections.ArrayList();
list.Add(Day.Monday);
Console.WriteLine ($"First elt is a {list[0].GetType()}");
var array = list.ToArray(typeof(Day));
foreach (var x in array)
Console.WriteLine ($"{x}");;
public enum Day { Monday, Tuesday } <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<UseMonoRuntime>true</UseMonoRuntime>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project> Issue happens with both the JIT and the interpreter (as expected) |
When we have to resort to checking element by element, compare the type of each actual element with the destination type. In particular, not the destinations underlying type when it's an enum - we don't want to allow unrelated enums using the same representation to copy over. Fixes dotnet#64387
When we have to resort to checking element by element, compare the type of each actual element with the destination type. In particular, not the destinations underlying type when it's an enum - we don't want to allow unrelated enums using the same representation to copy over. Fixes #64387
* Add regression test for object[] -> Int32Enum[] array copy where each element in the source array is the appropriate type * Fix downcast check in slow array copy When we have to resort to checking element by element, compare the type of each actual element with the destination type. In particular, not the destinations underlying type when it's an enum - we don't want to allow unrelated enums using the same representation to copy over. Fixes #64387
* Add regression test for object[] -> Int32Enum[] array copy where each element in the source array is the appropriate type * Fix downcast check in slow array copy When we have to resort to checking element by element, compare the type of each actual element with the destination type. In particular, not the destinations underlying type when it's an enum - we don't want to allow unrelated enums using the same representation to copy over. Fixes #64387 Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
Is there an existing issue for this?
Describe the bug
Code snippet:
ArrayList list = new ArrayList();
list.Add(Day.Monday);
var array = list.ToArray(typeof(Day));
public enum Day { Monday, Tuesday }
This is working fine in .net 6 desktop. But in Blazor WebAssembly, it throws exception System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type.
list.ToArray() without type is fine. But we are using type which is loaded in runtime, so the type is required.
Expected Behavior
Array created without exception
Steps To Reproduce
https://github.com/jjzhang12/WasmToArrayIssue.git
I added above code snippet to index page and you can observe the exception.
Also the .net console app is working fine.
Exceptions (if any)
System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type.
.NET Version
6.0.101
Anything else?
No response
The text was updated successfully, but these errors were encountered: