code_junkie

MethodAccessException on CF 2.0 List<T>.Sort

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public static class LibraryClass
  2. {
  3. public static void Test<T>(T foo, T bar)
  4. {
  5. // vastly simplified... I am aware that it is already in order here ;-p
  6. var list = new List<Wrapper<T>>();
  7. list.Add(new Wrapper<T> { Tag = 1, Value = foo });
  8. list.Add(new Wrapper<T> { Tag = 2, Value = bar });
  9.  
  10. list.Sort((x,y) => x.Tag.CompareTo(y.Tag)); // BOOM!!
  11. }
  12. }
  13.  
  14. public class Wrapper<T> // public to prove this isn't a factor...
  15. {
  16. public T Value { get; set; }
  17. public int Tag { get; set; }
  18. }
  19.  
  20. public static class Program
  21. {
  22. static void Main()
  23. {
  24. MyData foo = new MyData {Name = "foo"},
  25. bar = new MyData {Name = "bar"};
  26.  
  27. LibraryClass.Test<MyData>(foo, bar);
  28. }
  29. }
  30.  
  31. class MyData // but make MyData public and it works...
  32. {
  33. public string Name { get; set; }
  34. }
Add Comment
Please, Sign In to add comment