【发布时间】:2023-03-03 17:39:01
【问题描述】:
exe 调用 dll,但未明确使用已删除的接口。为什么旧 DLL 编译的 EXE 不能在新 DLL 运行时运行?
编译器必须保留有关类型的额外信息,而不仅仅是使用什么。
EXE
void main()
{
new Foo().PrintHello();
}
旧 DLL:
public class Foo : IOldInterface
{
public void PrintHello()
{
Console.WriteLine("Hello");
}
public int Something { get { return 123; } }
}
public interface IOldInterface
{
int Something { get; }
}
新建 DLL
public class Foo
{
public void PrintHello()
{
Console.WriteLine("Hello");
}
}
【问题讨论】:
-
我无法重现您提供的代码的问题 - 但我不得不更改它以使其编译这一事实表明您可能还没有使用此代码进行测试。请提供一个minimal reproducible example 来实际演示问题。
-
很抱歉。你说得对。我是从一个更大的代码库中推断出来的,并没有编译它。在有效放弃此问题之前更新了帖子。
标签: .net dll types interface compilation