Hi,
I've got a project where we pull a DLL's source code from a central
database and compile or recompile it, but if it's been executed it will not
recompile.
Steps.
1. Get Source code.
2. Compile Source code.
2.a Dispose Compiler.
3. Create new AppDomain
4. Execute the new DLL in the new AppDomain using Shadow Copy.
5. Unload the new AppDomain
Scenario 1.
Get source code, Compile, don't use.
Get new source code , compile don't use.
The Compiler overrights the old compiled dll with the new one
without a problem
Scenario 2.
Get source code, Compile, Load and execute.
Get Source code , Compile ... Exception.
Getting the source code and compiling creates the new dll, then the
shadow copy copies to a directory cache/MyAppDomain/runOnce/Assembly/....
Compiling a second time says that the dll is still in use.
error CS0016: Could not write to output file
'c:\Projects\compiler\testCompiler\bin\debug\demoEngine.dll' - 'The process
cannot access the file because it is being used by another process'
Does anyone know how to release the lock on the dll that is shadowcopied?
by rights it shouldn't even have a lock on it as it's been copied to the
cache directory and executed from there. Someone must have come across this
before, what magic bit of code am I missing.
<code>
//Creates and releases the appdomain after loading the dll one time.
public static object ExecuteAndRelease(string workingDirectory, string
dllName, string className, System.Collections.ArrayList methodParameters)
{
if(workingDirectory.Length == 0)
{
workingDirectory = System.Environment.CurrentDirectory;
}
AppDomain domain = CreateDomain("runOnce",workingDirectory);
IPluginCode plugin = GetObject(domain, dllName, className);
object ret = plugin.Execute(methodParameters);
AppDomain.Unload(domain);
domain = null;
return ret;
}
// The compiler.
CompilerParameters compilerParameters = new CompilerParameters(references,
string.Format(map,outputDirectory,outputFile),false);
compilerParameters.GenerateExecutable = false;
CompilerResults results =
codeCompiler.CompileAssemblyFromSource(compilerParameters,
csSourceCode);
</code>
Thanks.
--
Dave Jones
[EMAIL PROTECTED]
[EMAIL PROTECTED]
b1xml2 : "The one thing that is differentiates VB.NET from C# is the
horrible ability to do this turn Option explicit and strict off, after which
VB.NET can resemble mangled spaghetti. "
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com