Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0

前端 未结 9 1293
情书的邮戳
情书的邮戳 2020-12-01 09:13

I have a .NET Standard 1.4 class library that references the System.ComponentModel.Annotations (4.3.0) NuGet package.

I\'m then referencing this class library from a

9条回答
  •  天命终不由人
    2020-12-01 09:36

    Got it working by using assembly redirection as described in: just invoke FunctionsAssemblyResolver.RedirectAssembly() in the begining of your program. https://stackoverflow.com/a/50776946/2705777

    using System.Reflection;
    using System.Diagnostics;
    using System.Linq;
    
    public class FunctionsAssemblyResolver
    {
        public static void RedirectAssembly()
        {
            var list = AppDomain.CurrentDomain.GetAssemblies().OrderByDescending(a => a.FullName).Select(a => a.FullName).ToList();
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        }
    
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var requestedAssembly = new AssemblyName(args.Name);
            Assembly assembly = null;
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            try
            {
                assembly = Assembly.Load(requestedAssembly.Name);
            }
            catch (Exception ex)
            {
            }
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            return assembly;
        }
    
    }
    

提交回复
热议问题