Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 装配问题_C# - Fatal编程技术网

C# 装配问题

C# 装配问题,c#,C#,嗨,我在组装方面有问题 我有一个程序,创建了一个类。在这个类中,我使用difrent DLL中的一些其他类。在那个DLL类方法中,我必须使用汇编类,但我将引用程序汇编,我不知道如何做 如果在dll i user Assembly.GetExecutionGassembly或CallingAssembly中,我始终获得dll程序集:/ GetEntryAssembly始终执行StackOverFlow异常 在DLL中,我无法与该程序建立任何连接 编辑: 动态链接库 程序代码 在MapperSet中

嗨,我在组装方面有问题

我有一个程序,创建了一个类。在这个类中,我使用difrent DLL中的一些其他类。在那个DLL类方法中,我必须使用汇编类,但我将引用程序汇编,我不知道如何做

如果在dll i user Assembly.GetExecutionGassembly或CallingAssembly中,我始终获得dll程序集:/

GetEntryAssembly始终执行StackOverFlow异常

在DLL中,我无法与该程序建立任何连接

编辑:

动态链接库

程序代码


在MapperSet中有一些方法。当我调用其中一个时,我必须从IMapper类中获得ConnectionString和DbType。

如何将附属程序集的引用添加到主程序集,然后您可以直接使用这些类型作为解决方法,您可以让主程序集将正确的程序集传递到引用的dll,但是GetEntryAssembly也应该可以工作

我想Lasee是对的,你的代码肯定还有其他问题。告诉我们代码和堆栈跟踪

编辑:

在DLL中,可以从条目程序集中实例化类型。其中一个是DB类,它在参数初始化期间构造了MapperSet。这反过来会调用MapperSet构造函数,这会导致DLL加载条目程序集并永久递归地实例化其类型,因此会出现堆栈溢出异常

在构造函数中设置映射器如何:

public class DB : IMapper
{
     public MapperSet<Person> Persons = null;
     public DB()
     {
         Persons = new MapperSet<Person>(this);
     }       
     (...)
}
动态链接库:


您可能还想考虑使用依赖注入。

- 1:您的意思是他需要从主程序集、到另一个程序集、从另一个组件返回到主程序集的引用?很抱歉,不可能。不可能,如果M将是您的主程序集,而S是您的附属程序集,则可以添加从S到M的引用,并在M中动态加载S。然后可以枚举提供特定接口的所有类型、创建对象等。S可以访问M中的所有类型。您是否100%确定它正在调用生成堆栈溢出异常的GetEntryAssembly?你能显示你调用它的代码吗?删除了[assembly]标签;它用于汇编语言问题。
  public class DB : IMapper
  {
    public string ConnectionString
    {
      get { return "TestConnectionString"; }
    }

    public DBTypes DbType
    {
      get { return DBTypes.MsSql; }
    }

    public MapperSet<Person> Persons = new MapperSet<Person>();
    public List<int> l1 = new List<int>();
  }
public class DB : IMapper
{
     public MapperSet<Person> Persons = null;
     public DB()
     {
         Persons = new MapperSet<Person>(this);
     }       
     (...)
}
public sealed class MapperSet<T> : MapperSetBase<T>, IMapperSet<T>
{
    public MapperSet(IMapper mapper)
    {
        _Mapper = mapper;
    }
}