【问题标题】:How to have an interface over 2 .net projects using 2 different versions of a dll如何使用 2 个不同版本的 dll 在 2 个 .net 项目上建立接口
【发布时间】:2019-08-10 23:30:00
【问题描述】:

我继承了一个已有几年历史的 vb.net 应用程序,并且必须对其进行更新才能将订单发送到 3rd 方系统的 2 个版本。

  • 项目 A(现有)在 .net framework 3.5 中使用第 3 方 dll。
  • 项目 B(A 的新克隆)在 .net 4.7 中使用更新版本的 3rd 方 dll。

  • 项目主要(新)引用项目 A 和 B 以及解决方案中的 3 个其他项目;实体、数据访问和核心。 Project Main 有一个 SendTo 函数,可以发送到 Project A 或 Project B SendTo 函数。

  • 项目核心(新)引用实体和数据访问项目以及新的第 3 方 dll。

它有一个接口:

Imports Entities
Public Interface IOrderService
Function SendTo(...) as Order
End Interface

引用实体项目 (.net 4.7)

还有另一个界面:

Public Interface IClientSessionProvider
Function LogonService() as LogonService
...
End Interface

等等。它引用了新的第 3 方 dll。

如果我尝试在项目 A 中使用新的 .dll 并制作 .net 框架 4.7,则在使用其中一个 .dll 函数时会出现“应用程序错误”错误。此功能在项目 B(使用新的 .dll)中完美运行。

我怎样才能最好地组织代码,使项目 A 保持 3.5,其他一切保持 4.7 并且我的解决方案可以根据需要与两个 .dll 通信?

是否可以保留我的界面,以便代码仍然可以根据需要调用项目 A 或 B 中的方法,或者有其他方法可以解决这个问题吗?

【问题讨论】:

标签: .net


【解决方案1】:

我设法通过使用 Assembly.LoadFrom 使两个 dll 都正常工作,这是我的代码的摘录:

Dim params() As Object = New Object() {configuration, orderSaverService}

Dim assembly As Assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "\\<dll name here>.dll")
Dim myType As Type = assembly.GetType("<dll name + namespace here>", True)
objOrder = System.Activator.CreateInstance(myType, params)
appDomainOrder = AppDomain.CreateDomain()
iexecute = DirectCast(objOrder, IExecute)

其中 IExecute 是我在项目 A 和 B 中实现的新接口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 2010-12-26
    相关资源
    最近更新 更多