public void DuplicateCodeCompilatiion() { var cSharpLang = new CSharpCompilationManager(); var compilationSimple = cSharpLang.CreateAssemblyCompilation(_clownedCode, "DuplicateInMemoryAssembly", _referencedAssemblyPaths); var assemblyStreamSimple = cSharpLang.GetAssemblyStream(compilationSimple, out var diagnosticsSimple); System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromStream(assemblyStreamSimple); try { var compilationSimpleDuplicate = cSharpLang.CreateAssemblyCompilation(_clownedCode, "DuplicateInMemoryAssembly", _referencedAssemblyPaths); var assemblyStreamDuplicate = cSharpLang.GetAssemblyStream(compilationSimpleDuplicate, out var diagnosticsCloned); System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromStream(assemblyStreamDuplicate); Assert.Fail("Duplicate namespace should not be loaded"); } catch { } cSharpLang.CompileCodeAndLoadAssemblyIntoContext(_clownedCode, _referencedAssemblyPaths); var exampleClassCloneType = AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic) .SelectMany(a => a.GetTypes().Where(t => t.FullName == "ExampleNS.ExampleClassClown")); Assert.IsTrue(exampleClassCloneType.Count() == 2); }
public void ComplileAndLoadAssemblyTest() { var cSharpLang = new CSharpCompilationManager(); //All in one function Assert.IsTrue(cSharpLang.CompileCodeAndLoadAssemblyIntoContext(_clonedCode, _referencedAssemblyPaths)); }