使用MAF的AppDomainUnloadedException(Microsoft Addin Framework)

时间:2014-07-21 00:58:32

标签: c# .net remoting maf system.addin

我在调用使用MAF(System.AddIn)托管的插件时,在某些计算机上不时有AppDomainUnloadedExcpetion。这就是我的管道:

[AddInContract] 
public interface IGatewayV2 : IContract
{
     ITopUpResultContract TopUpPhoneAccount(ITopUpRequestContract request);
}

这是我的主机适配器:

[HostAdapterAttribute()]
public class GatewayContractToViewHostSideAdapter : Dogs.Pipeline.HostView.IGatewayV2
{
    private Dogs.Pipeline.Contracts.IGatewayV2 _contract;
    private ContractHandle _handle;

    public GatewayContractToViewHostSideAdapter(Dogs.Pipeline.Contracts.IGatewayV2 contract)
    {
        _contract = contract;
        _handle = new ContractHandle(contract);
    }

    public TopUpResult TopUpPhoneAccount(TopUpRequest request)
    {
        var topupRequestViewToContractHostSideAdapter = new TopUpRequestViewToContractHostSideAdapter(request);

        return
            new TopUpResultContractToViewHostSideAdapter(
                _contract.TopUpPhoneAccount(topupRequestViewToContractHostSideAdapter));

    }
}
总是在主机适配器端我有一个topupRequestViewToContractHostSideAdapter:

class TopUpRequestViewToContractHostSideAdapter : ContractBase, ITopUpRequestContract
{
    private TopUpRequest _topUpRequest;

    public TopUpRequestViewToContractHostSideAdapter(TopUpRequest topUpRequest)
    {
        this._topUpRequest = topUpRequest;
    }

    //properties here
)

和TopUpResultContractToViewHostSideAdapter处理对外部appdomain的引用:

  public class TopUpResultContractToViewHostSideAdapter : TopUpResult
  {
    private ITopUpResultContract _contract;
    private ContractHandle _handle;

    public TopUpResultContractToViewHostSideAdapter(ITopUpResultContract contract)
    {
        this._contract = contract;
        _handle = new ContractHandle(contract);
    }

    //properties here
  }

在插件方面,我有以下代码:

[AddInAdapter()]
public class GatewayViewToContractAddInSideAdapter : ContractBase, Dogs.Pipeline.Contracts.IGatewayV2
{
    private Dogs.Pipeline.AddinViewV2.IGatewayV2 _view;

    public GatewayViewToContractAddInSideAdapter(Dogs.Pipeline.AddinViewV2.IGatewayV2 view)
    {
        this._view = view;
    }

    public ITopUpResultContract TopUpPhoneAccount(ITopUpRequestContract request)
    {
        var result = _view.TopUpPhoneAccount(new TopUpRequestContractToViewAdapter(request));
        return new TopUpResultViewToContractAdapter(result);
    }
}

TopUpResultViewToContractAdapter是:

public class TopUpResultViewToContractAdapter : ContractBase, ITopUpResultContract
{ 
    private TopUpResult _topUpResult;

    public TopUpResultViewToContractAdapter(TopUpResult result)
    {
        this._topUpResult = result;
    }

    //properties here
}

并且TopUpRequestContractToViewAdapter是:

public class TopUpRequestContractToViewAdapter : TopUpRequest
{
    private ITopUpRequestContract _contract;
    private ContractHandle _handle;

    public TopUpRequestContractToViewAdapter(ITopUpRequestContract contract)
    {
        _contract = contract;
        _handle = new ContractHandle(contract);
    }

    //properties here
}

所有内容似乎都符合我目前所阅读的内容,尤其是我在此链接中可以阅读的内容:http://msdn.microsoft.com/en-us/library/bb384186(v=vs.100).aspx 所以我想知道我是做错了什么,或者管道在某些机器上不起作用的可能性(因为我在所有机器上都没有问题我和#39 ; m用于测试)。

感谢任何提示。

0 个答案:

没有答案