Object
namespace BlazorBug
{
public class Tag
{
public Tag(string value) => Value = value;
public string Value { get; }
/*
* BUG!
*
* This implicit operator causes InvalidCastException:
* Unable to cast object of type 'System.String' to type 'BlazorBug.Tag'.
*
* Comment the code below to avoid the exception.
*/
public static implicit operator string(Tag tag) => tag.Value;
}
}
Component
<h3>Tag Editor</h3>
<p>@Tag</p>
@code {
[Parameter]
public Tag Tag { get; set; }
}
Assignment
@page "/"
<TagEditor Tag="Tag" />
@code {
public Tag Tag { get; } = new Tag("My Tag");
}
Exception
InvalidCastException: Unable to cast object of type 'System.String'
to type 'BlazorBug.Tag'.
InvalidOperationException: Unable to set property 'Tag' on object of type
'BlazorBug.Shared.TagEditor'. The error was: Unable to cast object of type
'System.String' to type 'BlazorBug.Tag'.
Sample project
BlazorBug.zip
Object
Component
Assignment
Exception
Sample project
BlazorBug.zip