C#C
C#4y ago
LukeJ

✅ Invalid cast between interface types

Hello. I'm trying to learn functional programming in C#, so I'm ending up with some unusual code. A part of that is having an array of options marked with their length, like so
IMarked<Arr<Option<Unit>>, CountOfField>

Since this is so long, I've defined this
public interface FieldUnits : IMarked<Arr<Option<Unit>>, CountOfField> {}

This inevitably means casting to FieldUnits at some point, and doing so is giving me this error
System.InvalidCastException: 'Unable to cast object of type 'Marked`2[LanguageExt.Arr`1[LanguageExt.Option`1[Unit]],CountOfField]' to type 'FieldUnits'.'

I'm not sure why though, since they seem to be the same. I also swear this was working the other day. Any ideas what's wrong here? Here's a sample line that has this problem
var units = (FieldUnits)Enumerable.Repeat(Option<Unit>.None, CountOfField.Count).ToArr().mark(default(CountOfField));
Was this page helpful?