protected override void DoSaveCompiledState(out byte[] pe, out byte[] pdb){
pe = null;
pdb = null;
if (this.rawPE == null){
try{
// Save things out to a local PE file, then read back into memory
// PEFileName was set in the Compile method and we must have compiled in order to be calling this
if (!Directory.Exists(this.tempDirectory))
Directory.CreateDirectory(this.tempDirectory);
this.compilerGlobals.assemblyBuilder.Save(Path.GetFileName(this.PEFileName),
this.PEKindFlags, this.PEMachineArchitecture);
string tempPDBName = Path.ChangeExtension(this.PEFileName, ".ildb");
try{
FileStream stream = new FileStream(this.PEFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
try{
this.rawPE = new byte[(int)stream.Length];
stream.Read(this.rawPE, 0, this.rawPE.Length);
}finally{
stream.Close();
}
// genDebugInfo could have been changed since we compiled, so check to make sure the symbols are there
if (File.Exists(tempPDBName)){
stream = new FileStream(tempPDBName, FileMode.Open, FileAccess.Read, FileShare.Read);
try{
this.rawPDB = new byte[(int)stream.Length];
stream.Read(this.rawPDB, 0, this.rawPDB.Length);
}finally{
stream.Close();
}
}
}finally{
File.Delete(this.PEFileName);
if (File.Exists(tempPDBName))
File.Delete(tempPDBName);
}
}catch(Exception e){
throw new VsaException(VsaError.SaveCompiledStateFailed, e.ToString(), e);
}catch{
throw new VsaException(VsaError.SaveCompiledStateFailed);
}
}
pe = this.rawPE;
pdb = this.rawPDB;
}