From 52c445ca2a8d666c09c4ed8b133e43509a116208 Mon Sep 17 00:00:00 2001 From: Beej <6301228+Beej126@users.noreply.github.com> Date: Mon, 18 May 2020 23:39:49 -0700 Subject: [PATCH 1/2] bug fix avoids error: "NotSupportedException: The invoked member is not supported in a dynamic module" --- source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs b/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs index f0bf364..48817be 100644 --- a/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs +++ b/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs @@ -124,6 +124,7 @@ private Assembly Compile(IEnumerable 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); From d4a68bcea90d4789f0a3d771ccd0b90b2b33c289 Mon Sep 17 00:00:00 2001 From: Beej <6301228+Beej126@users.noreply.github.com> Date: Mon, 18 May 2020 23:45:51 -0700 Subject: [PATCH 2/2] some NETCORE vs NETFRAMEWORK ifdefs --- .../Interop/ComInterfaceAssemblyProvider.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs b/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs index 48817be..939acd0 100644 --- a/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs +++ b/source/VirtualDesktop/Interop/ComInterfaceAssemblyProvider.cs @@ -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; @@ -136,7 +138,12 @@ private Assembly Compile(IEnumerable 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);