0

I have a VSTO Word Addin project which integrates with the Word 2007, when I click on login button on my Addin, I execute the following method:

    private void btnOK_Click(object sender, System.EventArgs e)
    {
        AuditDataAccess auditDataAccess = 
(AuditDataAccess)DataAccessFactory.GetNewInstance(typeof(AuditDataAccess));
    }

Here, DataAccessFactory is a class in another referenced assembly named RemoteData as follows:

public class DataAccessFactory
{
    static DataAccessFactory()
        {
            objADDataAccess = new ADDataAccess();
        }
}

Here, ADDataAccess is a class in the same assembly RemoteData as:

namespace RemoteData.Client
{
    public class ADDataAccess : IDataAccess
        {
            RemoteData.Server.ADDataAccess proxy = null;

            internal  ADDataAccess()
            {
                proxy = new RemoteData.Server.ADDataAccess(); // Error Line
            }
         }

public interface IDataAccess
    {
        bool IsActive
        {
            get;
        }
    }

}

Server.ADDataAccess is in the same assembly RemoteData as:

namespace RemoteData.Server
{
    public class ADDataAccess:DataAccess
    {
        DataAccess.ADDataAccess objDataAccess;


        public ADDataAccess()
        {
            //objDataAccess = new DataAccess.ADDataAccess();
        }
    }
public abstract class DataAccess : MarshalByRefObject
    {
        public bool IsActive
        {
            get { return true; }
        }
    }
}

I have commented the code for new DataAccess.ADDataAccess() which is creating a new object of a class in another reference assembly named DataAccess, thinking that this might be the one creating the problem, but I am still receiving the same error mentioned in the question header on the line commented as Error Line

EDIT: I have created a small project with the same architecture and it is working fine. Here is the download link: http://www.2shared.com/file/dGXNtsAK/Server.html

Please please help...

4

1 回答 1

2

此问题已解决。问题是在Project.dll.config文件中,有一个这样的远程配置:

<system.runtime.remoting>
        <application>
            <channels>
                <channel ref="http">
                    <clientProviders>
                        <formatter ref="binary"/>
                    </clientProviders>
                </channel>
            </channels>
            <client url="" displayName="">
                <activated />
            </client>
        </application>
    </system.runtime.remoting>

因为,我们直接实例化了通过其中的<activated/>元素公开的类型,而不是通过远程调用获取它们,所以它导致了异常。在 中评论了整个远程配置部分后web.config,它开始工作。

于 2013-04-29T16:47:27.610 回答