MethodAccessException in CF 2.0 <T> .Sort List
I have a library code that works in the .NET runtime range (regular, CF, Silverlight, etc.), but a small block of code only breaks into CF 2.0 using MethodAccessException. I'm sure this is a runtime error, but does anyone know of any good workarounds? It works fine in CF 3.5, but I also need to support CF 2.0.
In particular, this applies to the assembly of the library using generics, while the caller gets non-public T. I do not do anything unpleasant for T(for example, reflection), but it still breaks ...
All he does is wrap the values ββand add them to the list, then sort the list with Comparison<>. I also tried Array.Sort,
IComparer<Wrapper<T>>, IComparable<Wrapper<T>>etc. - all fail in the same way: MethodAccessException- with VS tip:
If the access level of the method in the class library has changed, recompile any assemblies that reference the library.
But make it Tpublic, and it all works great ... note that we never sorted on T- we only worked with Wrapper<T>...
Any input is appreciated ...
Library assembly:
public static class LibraryClass
{
public static void Test<T>(T foo, T bar)
{
// vastly simplified... I am aware that it is already in order here ;-p
var list = new List<Wrapper<T>>();
list.Add(new Wrapper<T> { Tag = 1, Value = foo });
list.Add(new Wrapper<T> { Tag = 2, Value = bar });
list.Sort((x,y) => x.Tag.CompareTo(y.Tag)); // BOOM!!
}
}
public class Wrapper<T> // public to prove this isn't a factor...
{
public T Value { get; set; }
public int Tag { get; set; }
}
Build call:
public static class Program
{
static void Main()
{
MyData foo = new MyData {Name = "foo"},
bar = new MyData {Name = "bar"};
LibraryClass.Test<MyData>(foo, bar);
}
}
class MyData // but make MyData public and it works...
{
public string Name { get; set; }
}