代码之家  ›  专栏  ›  技术社区  ›  Mert Serimer

在.NET库项目中使用命名空间引用动态dll路径更改

  •  0
  • Mert Serimer  · 技术社区  · 6 年前

    我有 类库.net项目(没有配置,没有exe文件) 我有这样的东西;

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Reflection;
    using System.Web.UI.WebControls;
    using eBAControls; *<-- I want this dll to be loaded from a path in runtime.*
    

    我必须 copyLocal false 因此,出于将来的原因,我需要能够在运行时引用dll。与此当前dll位于同一文件夹中的其他第三方dll 不会引起任何问题 但是 eBAControls dll与当前dll不在同一文件夹中,因此它会给出错误: Could not load file or assembly 'eBAControls ...

    由于某些编码和性能原因,我也不能使用反射,因此需要将其添加到引用中。。。

    很快我想要的是

    using eBAControls = @"somepath"; <- that is set dynamically for ex while one of my methods are being executed etc...
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   David Browne - Microsoft    6 年前

    如果将事件处理程序放置在 AppDomain.AssemblyResolve . 见 Resolving Assembly Loads

    这是一篇有要点的博客文章。关键是时机。你必须附加事件 之前 引用程序集的第一个方法将被jitte。 https://blogs.msdn.microsoft.com/dbrowne/2014/06/25/how-to-load-an-assembly-in-a-ssis-script-task-that-isnt-in-the-gac/