Create and execute a LINQPad class/method in separate AppDomain


I'm trying to prototype some code in everyone's favorite prototyping IDE (LINQPad). I want to run a class I've created in the script in a separate AppDomain. For example:

void Main()
    AppDomain domain = AppDomain.CreateDomain("MyDomain");
    var qry = (AdHocQuery)domain.CreateInstanceAndUnwrap( typeof( AdHocQuery ).Assembly.Location, typeof( AdHocQuery ).FullName );


class AdHocQuery
    public void Run()

I get the following exception: FileLoadException: Could not load file or assembly 'C:\\Users\\terry.aney\\AppData\\Local\\Temp\\LINQPad5\\_jpomhdlf\\query_onuisp.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

Is it possible to do this in LINQPad?

asked on Stack Overflow Jun 19, 2020 by Terry

1 Answer


Answering my own question, even though it is from a tweet from Joe Albahari :)

Given that you're specifying assembly location rather than name, use CreateInstanceFromAndUnwrap. Also, use Util.CreateAppDomain instead of AppDomain.CreateDomain to make dependencies resolve. Add Util.NewProcess=true to query if you get type compatibility errors.

answered on Stack Overflow Jun 26, 2020 by Terry

User contributions licensed under CC BY-SA 3.0