如何使用ICLRStrongName :: StrongNameSignatureVerificationEx方法识别延迟签名的程序集
任何人都可以建议如何使用ICLRStrongName :: StrongNameSignatureVerificationEx方法来识别延迟签名的程序集。 我在互联网上找不到任何例子。 我不明白如何使用这种方法。
请不要向我推荐任何链接,我对网上提供的不同建议和不同链接感到沮丧。 任何人都可以为此提供代码示例。
我有同样的问题,终于找到了调查的时间。 我真的不明白为什么微软没有花时间写一份足够的文档。
以下链接非常有用,并且还包含一个示例项目,即使它也没有回答所有问题: http : //clractivation.codeplex.com/
我将尝试使用简短的代码示例回答所有问题。 您可以使用类似的东西来validation程序集的强名称:
public bool VerifyStrongName(string assemblyPath, bool force) { if (string.IsNullOrEmpty(assemblyPath)) throw new ArgumentException(string.Empty, "assemblyPath"); var host = HostingInteropHelper.GetClrMetaHost(); var bufferSize = 100; var version = new StringBuilder(bufferSize); var result = host.GetVersionFromFile(Assembly.GetExecutingAssembly().Location, version, ref bufferSize); if ((HResult)result != HResult.S_OK) throw new COMException("Error", result); IClrRuntimeInfo info = host.GetRuntime(version.ToString(), new Guid(IID.IClrRuntimeInfo)) as IClrRuntimeInfo; ICLRStrongName sn = info.GetInterface(new Guid(CLSID.ClrStrongName), new Guid(IID.IClrStrongName)) as ICLRStrongName; var verResult = sn.StrongNameSignatureVerificationEx(assemblyPath, Convert.ToByte(force)); return Convert.ToBoolean(verResult); }
您可以在ClrActivation示例项目中找到此示例中使用的所有分类和接口。
另外我把HRESULT课变成了一个枚举…
/// /// A set of common, useful HRESULTS, and related functionality /// public enum HResult { /// /// OK/true/Success /// S_OK = 0, /// /// False /// S_FALSE = 1, /// /// The method is not implemented /// E_NOTIMPL = unchecked((int)0x80004001), /// /// The interface is not supported /// E_NOINTERFACE = unchecked((int)0x80004002), /// /// Bad Pointer /// E_POINTER = unchecked((int)0x8004003), /// /// General failure HRESULT /// E_FAIL = unchecked((int)0x8004005), /// /// Invalid Argument /// E_INVALIDARG = unchecked((int)0x80070057), /// /// Insufficient buffer /// ERROR_INSUFFICIENT_BUFFER = unchecked((int)0x8007007A), /// /// HRESULT for failure to find or load an appropriate runtime /// CLR_E_SHIM_RUNTIMELOAD = unchecked((int)0x80131700), SEVERITY = unchecked((int)0x80000000) }
…并添加了静态分类的CLSID和IID (花了一些时间找到正确的CLSID):
public static class IID { public const string IClrRuntimeInfo = "BD39D1D2-BA2F-486A-89B0-B4B0CB466891"; public const string IClrMetaHost = "D332DB9E-B9B3-4125-8207-A14884F53216"; public const string IClrStrongName = "9FD93CCF-3280-4391-B3A9-96E1CDE77C8D"; public const string IEnumUnknown = "00000100-0000-0000-C000-000000000046"; } public static class CLSID { public const string ClrStrongName = "B79B0ACD-F5CD-409b-B5A5-A16244610B92"; }
我希望我能帮助你。 如果您还有其他问题,请随时提出。