Ash*_*mar 5 .net c# .net-assembly
任何人都可以建议如何使用ICLRStrongName :: StrongNameSignatureVerificationEx方法来识别延迟签名的程序集.我在互联网上找不到任何例子.我不明白如何使用这种方法.
请不要向我推荐任何链接,我对网上提供的不同建议和不同链接感到沮丧.任何人都可以为此提供代码示例.
小智 11
我有同样的问题,终于找到了调查的时间.我真的不明白为什么微软没有花时间写一份足够的文档.
以下链接非常有用,并且还包含一个示例项目,即使它也没有回答所有问题:http://clractivation.codeplex.com/
我将尝试使用简短的代码示例回答所有问题.您可以使用类似的东西来验证程序集的强名称:
public bool VerifyStrongName(string assemblyPath, bool force)
{
if (string.IsNullOrEmpty(assemblyPath))
throw new ArgumentException(string.Empty, "assemblyPath");
var host = HostingInteropHelper.GetClrMetaHost<IClrMetaHost>();
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);
}
Run Code Online (Sandbox Code Playgroud)
您可以在ClrActivation示例项目中找到此示例中使用的所有分类和接口.
另外我把HRESULT课变成了一个枚举...
/// <summary>
/// A set of common, useful HRESULTS, and related functionality
/// </summary>
public enum HResult
{
/// <summary>
/// OK/true/Success
/// </summary>
S_OK = 0,
/// <summary>
/// False
/// </summary>
S_FALSE = 1,
/// <summary>
/// The method is not implemented
/// </summary>
E_NOTIMPL = unchecked((int)0x80004001),
/// <summary>
/// The interface is not supported
/// </summary>
E_NOINTERFACE = unchecked((int)0x80004002),
/// <summary>
/// Bad Pointer
/// </summary>
E_POINTER = unchecked((int)0x8004003),
/// <summary>
/// General failure HRESULT
/// </summary>
E_FAIL = unchecked((int)0x8004005),
/// <summary>
/// Invalid Argument
/// </summary>
E_INVALIDARG = unchecked((int)0x80070057),
/// <summary>
/// Insufficient buffer
/// </summary>
ERROR_INSUFFICIENT_BUFFER = unchecked((int)0x8007007A),
/// <summary>
/// HRESULT for failure to find or load an appropriate runtime
/// </summary>
CLR_E_SHIM_RUNTIMELOAD = unchecked((int)0x80131700),
SEVERITY = unchecked((int)0x80000000)
}
Run Code Online (Sandbox Code Playgroud)
...并添加了静态分类的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";
}
Run Code Online (Sandbox Code Playgroud)
我希望我能帮助你.如果您还有其他问题,请随时提出.
| 归档时间: |
|
| 查看次数: |
1763 次 |
| 最近记录: |