Skip to content

ArrayList.ToArray(type) throws exception for enum type in Blazor WebAssembly #64387

@jjzhang12

Description

@jjzhang12

Is there an existing issue for this?

  • I have searched the existing issues

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions