一个wp7应用引用了Facebook csharp sdk 的dll, 传给FacebookClient的方法中使用了一个匿名类型,结果抛出MethodAccessException
使用匿名类型:
fb.PostAsync("oauth/access_token",new { client_id = AppId, client_secret = AppSecret, redirect_uri = RedirectUri, code = oauthResult.Code });异常代码:
foreach (var propertyInfo in parameters.GetType().GetProperties()) { if (!propertyInfo.CanRead) continue; dictionary[propertyInfo.Name] = propertyInfo.GetValue(parameters, null); }
异常原因: 匿名类型被编译为internal成员,跨程序集访问时会遇到此异常。
解决办法:可在使用匿名类型的程序集AssemblyInfo.cs中使用如下特性:
//make anonymous type in this assembly can be accessible by Facebook.dll [assembly: InternalsVisibleTo("Facebook")]
参考:
http://stackoverflow.com/questions/8273399/anonymous-types-and-get-accessors-on-wp7-1
http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx