gpt4 book ai didi

c# - 反射类型加载异常 : Type is attempting to implement an inaccessible interface

转载 作者:太空狗 更新时间:2023-10-29 20:11:44 24 4
gpt4 key购买 nike

我正在使用 Assembly.GetTypes() 获取插件库中定义的所有类型(因此我可以实例化插件实例)。

在特定库上,该方法引发 ReflectionTypeLoadException,说:

Type <Type> is attempting to implement an inaccessible interface

谷歌搜索似乎是因为特定的 Type 实现了一个非公共(public)接口(interface)。事实上它是,但 Type 嵌套在另一个公共(public)类中,声明为私有(private)。

如何避免这种异常?

....

使接口(interface)公开代码工作。是否可以将这种奇怪的行为定义为错误(在 Assembly.GetTypes() 中)?这意味着库类型无法实现 protected 接口(interface)!

最佳答案

通过从公共(public)类型中删除 protected 嵌套 类型解决了这个问题。

关于c# - 反射类型加载异常 : Type is attempting to implement an inaccessible interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4350363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com