Home

Util.Run() cannot run consecutive scripts with identical data connection

I have created a few daily jobs as separate .linq files which I call from a main .linq script which iterates all "Daily - *.linq" files in the same directory, runs them and e-mails me the result:

(this is a small part with the relevant faulting line)
  foreach (var file in Directory.EnumerateFiles(path, "Daily - *.linq"))
  {
    sb.AppendFormat("<h2>{0}</h2>", Path.GetFileNameWithoutExtension(file));
    sb.Append(Util.Run(file, QueryResultFormat.HtmlFragment).AsString());
  }
I noticed strange behavior in some LINQ files which I could not explain. The error message I get is:
Daily - [Script name]

System.Exception: error CS0006: Metadata file 'C:\Users\Administrator\AppData\Local\Temp\LINQPad\_hgtdtpol\TypedDataContext_tukxem.dll' could not be found

   at LINQPad.TaskExtensions.GetResult[T](Task`1 t)
   at LINQPad.ChildAppHost.GetResult()
   at LINQPad.ObjectModel.QueryExecuter.AsString()
   at UserQuery.Main() in d:\LINQPad\RunDaily.linq:line 24
Today I found out this is not specific to Task Scheduler, user account or lprun.exe as it seems reproducible in LINQPad itself, so I'll post it here.

Steps to reproduce the problem:
1. Create a LINQPad file with a data connection (e.g. LINQ-to-SQL), the command or expression is not relevant to the problem.

MyScript.linq:
<Query Kind="Expression">
  <Connection>
    <ID>60154894-9165-4f77-b527-0bc717db8966</ID>
    <Persist>true</Persist>
    <Server>(local)</Server>
    <NoPluralization>true</NoPluralization>
    <NoCapitalization>true</NoCapitalization>
    <Database>master</Database>
    <ShowServer>true</ShowServer>
  </Connection>
</Query>

"Test"
2. Create another LINQPad script which calls this script. In production, I'm calling different scripts with the same connection. To reproduce the problem, multiple runs to the same script is enought to reproduce the problem.
var path = Path.GetDirectoryName(Util.CurrentQueryPath);
var script = Path.Combine(path, "MyScript.linq");
for (var i = 0; i < 10; i++)
{
  Util.Run(script, QueryResultFormat.HtmlFragment).AsString().Dump();
}
3. Run the main script, this is the result:

<div>Test<br /></div>
<div>Test<br /></div>
<div>Test<br /></div>

6FileNotFoundException4
Could not load file or assembly file:///C:\Users\Administrator\AppData\Local\Temp\LINQPad5\_rcvluirq\TypedDataContext_kqzkmz.dll or one of its dependencies. 
I have found a workaround for this issue:
- Change the connection ID in the scripts that share the same connection.

Version(s) affected:
- v4.57.02
- v5.02.05

Comments

Sign In or Register to comment.