我隔离了以下用于分布式测量和数据解释的问题(当impl知道如何处理数据及其在示例表示它们时不存在的UserControl时。)>
我在解决方案中有3个不同的项目:1)界面(单独的dll)
namespace inter { public interface IInter { byte[] results(); } }
2)实现类(单独的dll)
using inter; namespace impl { public class impl : IInter { public byte[] results() {//dummy data production return new byte[10].Select((ii, index) => (byte)index).ToArray(); } } }
3)运行该问题的程序...
异常消息。 我如何使wotk脚本识别两个类类型是相同的。(注意。我无法将引用链接到项目中,实现impl类是用户的责任,所以我不这样做甚至都知道他们。using inter; using impl; namespace test_class_casting { class Program { static void Main(string[] args) { var path = @"C:\Users\pavel\source\repos\test class casting\impl\bin\Debug\impl.dll"; var b = File.ReadAllBytes(path); var assembly = Assembly.Load(b); IInter inst = null; var expTypes = assembly.GetExportedTypes(); foreach (var d in assembly.GetExportedTypes()) { var obj = Activator.CreateInstance(d); if (obj is IInter) { inst = obj as IInter; try { var res = inst.results(); continue; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); Environment.Exit(0); } } } try { var reType = (impl.impl)inst;// as impl.impl; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); Environment.Exit(0); } Console.WriteLine("..."); Console.ReadKey(); } } }
问题是reType转换将失败,因为[A] impl.impl无法转换为[B] impl.impl。
我甚至尝试在inter和impl中都添加一个强名称,但现在有了进展。您为此有解决方案吗?
我隔离了以下用于分布式测量和数据解释的问题(当impl知道如何处理数据及其示例中未提供的UserControl时...
毕竟,经过一些装配研究,我找到了解决方案。每次程序集动态加载时,代码可以检查它是否已经存在于AppDomain.CurrentDomain.GetAssemblies()中(通过FullName属性检查)。即如果程序集引用到项目。