I've been debugging this problem for hours and finally found the culprit for the problem. Let me explain the setup.
(I've got these interfaces and classes that implement them A,B)
public interface IA { public void DoSomething(int i); }
public interface IB : IA { public void SomethingElse(); }
(in some method in some class)
dynamic options = JSonConvert.DeserializeObject<dynamic>(json);
var id = int.Parse(options.someId.ToString());
IB b = new B();
b.DoSomething(id);
This code compiles as expect but at runtime I get "IB does not contain a definition for 'DoSomething'".
However, if I change to:
var id = 1;
IB b = new B();
b.DoSomething(id);
Then everything works!
Similar things have happened previously when I've used dynamic inside a method. What is going on here? Does anyone know?
Note: I can easily avoid this by moving the two lines into a different method or avoid using dynamic altogether but I'm just qurious to why :)
Fun fact: When I had 'DoSomething' and 'SomethingElse' inside one interface and one class this didnt cause any problems...