// note: this property *cannot* change TempDir property
string temp = tempdir;
- if (temp.Length == 0)
- temp = GetOwnTempDir ();
+ if (temp.Length == 0) {
+ if (ownTempDir != null) {
+ temp = ownTempDir;
+ Directory.CreateDirectory (temp);
+ } else {
+ temp = CreateOwnTempDir ();
+ }
+ }
// Create a temporary file at the target directory. This ensures
// that the generated file name is unique.
- FileStream f = null;
- do {
+ int test_counter = 1000;
+ while (true) {
int num = rnd.Next ();
num++;
basepath = Path.Combine (temp, num.ToString("x"));
string path = basepath + ".tmp";
try {
- f = new FileStream (path, FileMode.CreateNew);
- }
- catch (System.IO.IOException) {
- f = null;
- continue;
- }
- catch {
- // avoid endless loop
+ using (var f = new FileStream (path, FileMode.CreateNew)) {
+ break;
+ }
+ } catch (IOException) {
+ if (test_counter-- > 0)
+ continue;
+
throw;
}
- } while (f == null);
-
- f.Close ();
-
+ }
+
// and you must have discovery access to the combined path
// note: the cache behaviour is tested in the CAS tests
if (SecurityManager.SecurityEnabled) {
return(basepath);
}
}
-
- string GetOwnTempDir ()
- {
- if (ownTempDir != null)
- return ownTempDir;
+ string CreateOwnTempDir ()
+ {
// this call ensure the Environment permissions check
string basedir = Path.GetTempPath ();
}
if (allDeleted && ownTempDir != null) {
Directory.Delete (ownTempDir, true);
- ownTempDir = null;
}
}
Assert.AreEqual (tempFile, tempFiles[0], "#5");
}
+
+ [Test]
+ public void CompileFromSource_InMemory_Twice ()
+ {
+ CompilerParameters options = new CompilerParameters ();
+ options.GenerateExecutable = false;
+ options.GenerateInMemory = true;
+
+ ICodeCompiler compiler = _codeProvider.CreateCompiler ();
+
+ var src_1 = "class X { ";
+
+ CompilerResults results_1 = compiler.CompileAssemblyFromSource (options, src_1);
+ var output_1 = options.OutputAssembly;
+
+ var src_2 = "class X { }";
+
+ CompilerResults results_2 = compiler.CompileAssemblyFromSource (options, src_2);
+ var output_2 = options.OutputAssembly;
+
+ // verify compilation was successful
+ AssertCompileResults (results_2, true);
+
+ Assert.AreEqual (output_1, output_2, "#1");
+ }
+
[Test]
public void CompileFromSourceBatch_InMemory ()
{