I’ve got a List<Component> collection (Component is a custom class) with a single element that inherits from XTYPE.
But for some reason this doesn’t work:
X = (XTYPE)Components.Single((c) => c is XTYPE);
I get an InvalidOperationException with the message “Sequence contains no matching element”
But if I put in a breakpoint at that line and do this it returns true:
Components[0] is XTYPE
Furthermore if I do this it returns true:
Components[0].GetType().BaseType.BaseType == typeof(XTYPE)
Help.
OK, so I added a few checks into my code…
foreach (Component c in Components)
Console.WriteLine(c.GetType().BaseType.BaseType == typeof(Bridge));
if (Components.Count == 0)
throw new Exception("No components");
if (!(Components[0].GetType().BaseType.BaseType == typeof(Bridge)))
throw new Exception("Not bridge.");
False gets written to the console, but the type names are the same.
This is probably DLL hell. And now requires a diff set of information to answer the question.
I think you guys have helped me move toward my solution.
Further explanation: the Component in question was instantiated via reflection from a separate instance of the DLL that has XTYPE in it. So now we’ve got two XTYPEs but they technically aren’t the same type because they’ve got a diff typehandle.
The debugger wasn’t checking in the right context so it thought the types were the same. But it was wrong.
the Component in question was instantiated via reflection from a separate instance of the DLL that has XTYPE in it. So now we’ve got two XTYPEs but they technically aren’t the same type because they’ve got a diff typehandle.
The debugger wasn’t checking in the right context so it thought the types were the same. But it was wrong.