Home

Using two versions of a dll at the same time in LinqPad

I have several SQL databases using a 'Typed data context from my own assembly'. But I have one database which for various reasons I don't to upgrade to the latest schema version. Hence I want to access this using the older version of the dll. (Same filename, but different version).

If I open LinqPad and try to access the old database using the old dll in one query and try to access one of the new databases using the new dll in another query, am I likely to run into trouble?

The dll isn't strong named nor installed in GAC if that makes any difference.

Comments

  • Each query runs in its own application domain, so it can load its own mix of assemblies.

    Presumably the typed datacontext with the older DLL is in a different folder? If so, you'll need to create a different connection that points to that folder. To make it easier to identify which connection you're dealing with, you can rename connections using the option on the context menu.
  • Yes the typed datacontext will be on a different folder.

    Probably didn't explain myself very well.

    I understand that when I execute my query it runs in a different appdomain and hence is ok, but I was concerned about what happens beforehand, eg whilst writing the query. LinqPad must be accessing the typed datacontext dll for the intellisense to work. Even just expanding the connection must load the dll to build the list of classes/tables. Hence it would look like LinqPad would need to be accessing both dlls at the same stage.

    Is this part safe?




  • I'm not sure I understand. When you expand a connection, LINQPad loads the typed datacontext from the assembly you specify by calling (something functionally equivalent to) Assembly.LoadFrom.

    If you have two versions of an assembly in two different folders, LINQPad will load whichever assembly is in the folder that you point it to.

    Have I missed something?
  • > LINQPad will load whichever assembly is in the folder that you point it to.
    You say that like it is obvious, but it isn't obvious to me. For example if I have code like

    string dir1 = ..
    string dir2 = ..
    string dll = ..

    var a = Assembly.LoadFrom(Path.Combine(dir1 , dll));
    var b = Assembly.LoadFrom(Path.Combine(dir2 , dll));

    then, even through I am trying to load two different assemblies from two different folders, it will not work.

    If LinqPad created a new app domain every time you expanded a connection, then I can see how it would work, but it only appears to create a new app domain when I execute a query.

    Got to say, it appears to work, but I don't understand how and I don't like things I don't understand.

    Sorry to be a pain.
  • LINQPad does create a new app domain per connection (as well as a new app domain per query). Does that help?
  • If you're interested, LINQPad's application domain model is explained in detail here:
    http://www.linqpad.net/DataContextDrivers.docx

    See "Application Domains & Loading Assemblies"
  • LINQPad does create a new app domain per connection (as well as a new app domain per query). Does that help?
    Yes that helps. That was the info that I was missing.

    I'll read through the document later (when I have a clear head).

    Thanks again for your help.
Sign In or Register to comment.