Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
#if NETCORE //fix: https://stackoverflow.com/questions/45741039/could-not-load-file-or-assembly-system-runtime-loader-for-adding-application-p/54827796#54827796
using System.Runtime.Loader;
#endif
using System.Text;
using System.Text.RegularExpressions;
using WindowsDesktop.Properties;
Expand Down Expand Up @@ -124,6 +126,7 @@ private Assembly Compile(IEnumerable<string> sources)
var syntaxTrees = sources.Select(x => SyntaxFactory.ParseSyntaxTree(x));
var references = AppDomain.CurrentDomain.GetAssemblies()
.Concat(new[] { Assembly.GetExecutingAssembly(), })
.Where(x => !x.IsDynamic) //fix per this issue: https://stackoverflow.com/questions/44446720/notsupportedexception-the-invoked-member-is-not-supported-in-a-dynamic-module-i/44446796#44446796
.Select(x => x.Location)
.Select(x => MetadataReference.CreateFromFile(x));
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
Expand All @@ -135,7 +138,12 @@ private Assembly Compile(IEnumerable<string> sources)
var result = compilation.Emit(path);
if (result.Success)
{
#if NETCORE //fix: https://stackoverflow.com/questions/45741039/could-not-load-file-or-assembly-system-runtime-loader-for-adding-application-p/54827796#54827796
return AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
#endif
#if NETFRAMEWORK
return Assembly.LoadFile(path);
#endif
}

File.Delete(path);
Expand Down