Skip to content

Actions with generic-derived argument throw TypeLoadException when the type is initialised #51

@butler1233

Description

@butler1233

I just want to start off by saying this library is absolutely fantastic - it makes Blazor almost as magic as WPF with regards to binding stuff to the UI and it magically updating.

However, I ran into a somewhat niche issue with it when I was creating a razor component which included the following:

[Observable]
public ICollection<BetterKeyValuePair<string,string>> Options { get; set; }

(for reference, here's that type in all it's not exactly interesting glory)

public class BetterKeyValuePair<T1, T2>
    {
        public T1 Key { get; set; }
        public T2 Value { get; set; }

        public BetterKeyValuePair(T1 key, T2 value)
        {
            Key = key;
            Value = value;
        }

        public BetterKeyValuePair()
        {
            Key = default;
            Value = default;
        }
    }

I then had an action which was written like this;

[Action]
private void RemoveOption(BetterKeyValuePair<string,string> option)
{
    Options.Remove(option);
}

When I removed the [Action] attribute it worked, although then obviously it threw the whole "side effects are not allowed" which makes sense. But then I dropped the genericness from the BetterKeyValuePair (it probably won't ever be used aside from string,string anyway) and then it worked like a charm!

I'd have a stab at fixing it myself, and I might take a look later, but I thought I'd raise it first. I've asked somebody else who introduced me to this box of magic to verify that too.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions