Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppDomain.DoCallBack() with multi generic types issue

i've a strange issue with AppDomain.DoCallBack() and generic types:

static void InvokeIsolated() {
  AppDomain appDomain = AppDomain.CreateDomain("testDomain");
  appDomain.DoCallBack(MyDoCallBack<string, string>); <-- ArgumentNullException!
}

static void MyDoCallBack<T, T1>() {}

i get an argumentnullexpcetion with the message: "value cannot be null" when the generic types are the same.

if i change the docallback to this:

appDomain.DoCallBack(MyDoCallBack<string, int>); <-- OK!

that means if the generic types are different, there is no problem.

what is wrong or is this a .net bug??

UPDATE: lambda isn't a workaround if called with generic types:

static void Foo()
{
   InvokeIsolated<string, string>();
}

static void InvokeIsolated<T, T1>()
{
   AppDomain appDomain = AppDomain.CreateDomain("testDomain");
   appDomain.DoCallBack(() => MyDoCallBack<T, T1>()); //<--ArgumentNullException
}

static void MyDoCallBack<T, T1>() {}
like image 560
brainwave Avatar asked Nov 10 '22 18:11

brainwave


1 Answers

This is a bug in the .NET Remoting infrastructure. This is a crash in .NET internal code.

I don't have a good workaround. You could compile a non-generic wrapping function using expression trees. You would need one such lambda per set of generic type arguments.

like image 69
usr Avatar answered Nov 15 '22 05:11

usr