What does Util.NewProcess do underneath in LINQPad 6 (dotnet Core)?

edited January 2


I have a script that does some type casting like this in Linqpad6 running under .NET Core 3.1 to replicate an issue we have in production:

var p = (IAuditedEventModel)empRecDesrializedToObject;

First time I execute, it works fine but if I make changes to the script (e.g. adding a comment) and re-run I get this InvalidCastException:

Unable to cast object of type 'EmployeeRecordTypeChanged' to type 'IAuditedEventModel'.

I also noticed that after making change and re-running the script, some Assemblies, like the ones for LinqPad6Query are loaded multiple times.

If I add a Util.NewProcess = true; at the beginning, things work fine even after making changes to the script.

Since we are getting the same exception in an Azure Function in production I'd like to know what that NewProcess = true flag is doing? Is it creating a new AppDomain every time the script runs?



  • Setting Util.NewProcess to true asks LINQPad to create a new process for the next execution. This ensures that there's no residue from any previous run. You can make this the default in Edit | Preferences > Advanced. There's no big disadvantage in doing so - the main loss is a small performance hit and the inability to use the Util.Cache method to cache objects between executions REPL-style (there are examples on how to do this in LINQPad's inbuilt tutorial and reference).

    In your case, I suspect that empRecDesrializedToObject is somehow being cached and so you're trying to deserialize an object that was serialized in a previous execution. If you made changes to the script, the type will have been recompiled, and so the new type will not be compatible with the new type.

Sign In or Register to comment.