Question

I'm not able to execute code in another application domain in Linqpad:


void Main()
{
AppDomain.CreateDomain("AD").DoCallBack(() => { Console.WriteLine("Test"); });
}

I get a different file not found exception each time I execute the code:

Could not load file or assembly 'query_gclnfu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Could not load file or assembly 'query_blixbs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

I'm clueless...

Was it helpful?

Solution

LINQPad runs your code in an app domain via the simple sandboxing API, and this means that you'll run into permission issues if you create a domain using AppDomain.CreateDomain.

LINQPad offers a helper method to create an app domain with the right permissions and assembly resolution handlers set up:

Util.CreateAppDomain ("AD").DoCallBack(() => { Console.WriteLine("Test"); });

This will run without error, although you won't see "Test" appear in the output window because the new app domain won't have its console output redirected. The following will work, though:

Util.CreateAppDomain ("AD").DoCallBack(() => MessageBox.Show ("test"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top