我有一个程序,它为所有dll使用单声道补丁。
当我运行它时,会引发异常:
“无法加载文件或程序集”xxxxxxx,版本= 911.1.0.0, Culture = neutral,PublicKeyToken = xxxxxxxxxxxxxxx'或其中一个 依赖。定位程序集的清单定义没有 匹配程序集引用。 (来自HRESULT的异常:0x80131040)“。
我删除了所有程序集的强签名和相关引用的强签名。
调试后,该方法调用GetCustomAttribute
方法抛出异常,该异常属于GetCustomAttributes
接口的成员方法System.Reflection.ICustomAttributeProvider
。
我认为某些元数据中存在强大的签名信息,但我没有找到它。强大的签名数据保存在哪里?
代码:
private static IEnumerable<PageFreeHandler.PageFreePageInfo> FindAllPageFreePages(Assembly assembly)
{
foreach (Type type in assembly.GetTypes())
{
if (!type.IsAbstract)
{
PageFreeHandler.PageFreePageInfo pageFreePageInfo = new PageFreeHandler.PageFreePageInfo
{
PageType = type,
CanonicalUrlAttribute = type.GetCustomAttribute<CanonicalUrlAttribute>(),
AlternateUrlAttributes = new List<AlternateUrlAttribute>(type.GetCustomAttributes<AlternateUrlAttribute>()).ToArray(),
RegexUrlAttributes = new List<RegexUrlAttribute>(type.GetCustomAttributes<RegexUrlAttribute>()).ToArray()
};
if (pageFreePageInfo.CanonicalUrlAttribute != null || pageFreePageInfo.AlternateUrlAttributes.Length != 0 || pageFreePageInfo.RegexUrlAttributes.Length != 0)
{
yield return pageFreePageInfo;
}
}
}
Type[] array = null;
yield break;
}
public static class ReflectionExtensions
{
public static T GetCustomAttribute<T>(this ICustomAttributeProvider member) where T : Attribute
{
if (member == null)
{
throw new ArgumentNullException("member");
}
object[] customAttributes = member.GetCustomAttributes(typeof(T), true);
if (customAttributes.Length != 0)
{
return (T)((object)customAttributes[0]);
}
return default(T);
}
public static IEnumerable<T> GetCustomAttributes<T>(this ICustomAttributeProvider member)
{
if (member == null)
{
throw new ArgumentNullException("member");
}
return member.GetCustomAttributes(typeof(T), true).Cast<T>();
}
public static Type[] GetGenericArgumentsFromAncestor(this Type type, Type genericTypeDefinition)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (genericTypeDefinition == null)
{
throw new ArgumentNullException("genericTypeDefinition");
}
if (!genericTypeDefinition.IsGenericTypeDefinition)
{
throw new ArgumentException("genericTypeDefinition is not a generic type definition");
}
while (!type.IsGenericType || !(type.GetGenericTypeDefinition() == genericTypeDefinition))
{
type = type.BaseType;
if (!(type != null))
{
return Type.EmptyTypes;
}
}
return type.GetGenericArguments();
}
}