1

我想要一个C#库(库范围是与谷歌联系人API通信)与依赖关系嵌入式库中。谷歌联系人嵌入式DLL MissingMethodException

所以,在我的类的构造函数,我把这个代码:

AppDomain.CurrentDomain.AssemblyResolve += (sender, evento) => 
      { 
       var assemblyName = evento.Name.Split(',')[0].Trim(); 
       if (assemblyName.ToLower().Equals("google.gdata.contacts")) 
        return Assembly.Load(Assembly.GetExecutingAssembly().GetEmbeddedResource("Contacts.Assembly.Google.GData.Contacts.dll")); 
       else if (assemblyName.ToLower().Equals("google.gdata.client")) 
        return Assembly.Load(Assembly.GetExecutingAssembly().GetEmbeddedResource("Contacts.Assembly.Google.GData.Client.dll")); 
       else if (assemblyName.ToLower().Equals("google.gdata.extensions")) 
        return Assembly.Load(Assembly.GetExecutingAssembly().GetEmbeddedResource("Contacts.Assembly.Google.GData.Extensions.dll")); 
       else if (assemblyName.ToLower().Equals("newtonsoft.json")) 
        return Assembly.Load(Assembly.GetExecutingAssembly().GetEmbeddedResource("Contacts.Assembly.Newtonsoft.Json.dll")); 

       return null; 
      }; 

这样,当的AppDomain尝试解决谷歌联系人库或依赖我回到我的嵌入式汇编。 这工作!

我的问题是,当我把这个代码:

RequestSettings settings = new RequestSettings("ApplicationName"); 
ContactsRequest cr = new ContactsRequest(settings); 
Feed<Google.Contacts.Contact> f = cr.GetContacts(); 

此代码相同的工作RequestSettings(这个类是google.data.client.dll),但是当尝试创建ContactRequest实例(这个类是在google.data.contacts.dll)它引发“MissingMethodException”。

为什么代码返回这个错误?

+0

我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-12-15 00:44:48

回答

0

检查google.data.contacts.dll:大概这取决于你是不是包括(例如log4net的)另一个DLL。

检查你的内部异常,它应该包括它的细节。

0

我发现问题了!!!不同的是,每次调用者使用未引用的程序集时,都会引发AssemblyResolve事件。但是,在我的代码中,我每次加载相同的程序集,但对于AppDomain,它们是不同的程序集。在例如:

MYDLL提高AssemblyResolve加载:google.gdata.clientgoogle.gdata.contact 然后应用程序实例ContactRequest(google.gdata.contact)。但是这个DLL提高AssemblyResolve加载:google.gdata.client

对于AppDomain中google.gdata.client(在MYDLL加载)不同到google.gdata.client(加载google.gdata.contact) 。

要解决的问题,建立一个字典,所有的dll加载,所以当域名请求解析汇编代码返回曾经同大会