3

Possible Duplicate:
C# 4.0 dynamics

I have a function

void Foo(dynamic thingy)
{

  int bar = thingy.Id;
}

and I call it like this

Foo(new {Id=42, Color="red", size = "XL"});

This works fine when Foo and the caller are in the same assembly. But when they are not in the same assembly Foo fails at runtime with RuntimeBinderException saying

'object' does not contain a definition for 'Id'

pointing at the thingy.Id line. A watch in VS shows for sure it has an Id property. Any ideas?

EDIT: this is going to be closed dup. But I thought I would just record that fact that internalsvisibleto assembly attribute worked great - tx manji

Community
  • 1
  • 1
pm100
  • 48,078
  • 23
  • 82
  • 145
  • thats what I assumed it was. I guess the "internals visible to" is the way to go. BTW if you had made this an answer then I could accept it and you get shiny points – pm100 May 24 '11 at 00:27
  • Because it's an exact duplicate, it's better to close it and link it to the other question, to have all the answers in the same place. – manji May 24 '11 at 00:31

1 Answers1

0

Property names are case sensitive.

Could the invoker of Foo() be using new {id=42 ...}?

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73