Skip to content

Commit 89a98f8

Browse files
jgiannuzzimhutch
authored andcommitted
Load compiled assembly in memory and delete temporary folder
1 parent a2b8842 commit 89a98f8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ public CompiledTemplate (ITextTemplatingEngineHost host, CompilerResults results
5656

5757
void Load (CompilerResults results, string fullName)
5858
{
59-
//results.CompiledAssembly doesn't work on .NET core, it throws a cryptic internal error
60-
//use Assembly.LoadFile instead
61-
var assembly = System.Reflection.Assembly.LoadFile (results.PathToAssembly);
62-
Type transformType = assembly.GetType (fullName);
59+
Type transformType = results.CompiledAssembly.GetType (fullName);
6360
//MS Templating Engine does not look on the type itself,
6461
//it checks only that required methods are exists in the compiled type
6562
textTransformation = Activator.CreateInstance (transformType);

Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,19 @@ CompilerResults CompileCode (IEnumerable<string> references, TemplateSettings se
274274
r.Errors.AddRange (result.Errors.Select (e => new CompilerError (e.Origin ?? "", e.Line, e.Column, e.Code, e.Message) { IsWarning = !e.IsError }).ToArray ());
275275

276276
if (result.Success) {
277-
r.TempFiles.AddFile (args.OutputPath, true);
277+
r.TempFiles.AddFile (args.OutputPath, args.Debug);
278278
if (args.Debug) {
279279
r.TempFiles.AddFile (Path.ChangeExtension (args.OutputPath, ".pdb"), true);
280280
}
281-
r.PathToAssembly = args.OutputPath;
281+
// load the assembly in memory so we can fully clean our temporary folder
282+
r.CompiledAssembly = Assembly.Load (File.ReadAllBytes (args.OutputPath));
282283
} else if (!r.Errors.HasErrors) {
283284
r.Errors.Add (new CompilerError (null, 0, 0, null, $"The compiler exited with code {result.ExitCode}"));
284285
}
285286

286287
if (!args.Debug && !r.Errors.HasErrors) {
287288
r.TempFiles.Delete ();
289+
Directory.Delete (tempFolder);
288290
}
289291

290292
return r;

0 commit comments

Comments
 (0)