C#-在接口的GetCustomAttribute中找不到自定义属性

|| 我正在尝试设置如下的自定义属性:
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class AuthorizationAttribute : Attribute
{
    public AuthorizationAttribute(bool required)
    {
        Required = required;
    }

    public bool Required;
}
在我的服务合同界面中,我有一个类似这样的方法:
[OperationContract]
[Authorization(true)]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = \"randommethod\")]
ReturnObject RandomMethod();
当我执行以下操作时,我会在列表中看到它,但是\'is \'比较失败:
foreach(object attribute in methodInfo.GetCustomAttributes(true)) // Returns all 3 of my attributes.

if (attribute is AuthorizationAttribute) //Does not pass
我尝试执行以下返回false的操作:
Attribute.IsDefined(methodInfo, typeof(AuthorizationAttribute));
attribute.GetType().IsAssignableFrom(typeof(AuthorizationAttribute));
我还做了以下两件事,它们返回null:
AuthorizationAttribute authAttribute = attribute as AuthorizationAttribute;
Attribute attribute = Attribute.GetCustomAttribute(methodInfo, typeof(AuthorizationAttribute));
我不确定我在做什么错。似乎应该可以,但是我确信我在某个地方犯了一个简单的错误。有见识吗? 感谢您的协助。 编辑: 我不确定是否添加了任何含义,但是AuthorizationAttribute声明存在于与我的服务项目不同的项目中。服务合同接口与AuthorizationAttribute存在于同一项目中。 我尝试进行转换,并得到以下异常:
[A]Lib.OAuth.AuthorizationAttribute cannot be cast to [B]Lib.OAuth.AuthorizationAttribute. 
Type A originates from \'Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\' in the
context \'LoadNeither\' at location \'F:\\RestServices\\bin\\Lib.dll\'. Type B originates from \'Lib,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\' in the context \'Default\' at location 
\'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\Temporary ASP.NET Files\\oauth_rest\\951069b9
\\9f7b77fe\\assembly\\dl3\\54c48906\\f928a6ad_01facb01\\Lib.dll\'.
有任何想法吗?     
已邀请:
异常包含答案:   类型A源自...在位置\'F:\\ RestServices \\ bin \\ Lib.dll \'。 B型起源于...   \'C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\临时ASP.NET文件\\ oauth_rest \\ 951069b9   \\ 9f7b77fe \\ assembly \\ dl3 \\ 54c48906 \\ f928a6ad_01facb01 \\ Lib.dll \' 问题在于,在尝试进行强制转换的程序集中找到了属于您方法的“ 6”类型,该类型不同于在运行时加载的程序集。 您的项目之一是否正在使用旧版本的Lib.dll?     
感谢韦斯利的回应,我得以弄清楚这一点。这比什么都重要。 我使用一些示例代码进行反射,以通过Assembly.LoadFile(...)方法加载程序集。问题在于,由于我的程序集未在GAC中注册,因此它正在IIS服务器上读取本地副本,并且比较失败。 供参考,这是我的解决方案:
Assembly.GetExecutingAssembly();
一旦我做到了,一切都会正常。     

要回复问题请先登录注册