任何人都可以请建议如何使用 ICLRStrongName :: StrongNameSignatureVerificationEx 方法来确定延迟签名的程序集。我无法找到在互联网上的任何实例。我不理解如何使用这种方法的工作。
请不要参考我的任何一个环节,我有不同的意见和不同的链接在网上几乎可以在沮丧。任何人都可以请给code样品是一样的。
解决方案我有同样的问题,最后发现,调查时间。我真的不明白,为什么微软并没有花时间来写一个适当的文档。
下面的链接是非常有益的,还包含了一个示例项目,即使它也不能回答所有的问题:的http:// clractivation。codeplex.com /
我会尝试回答一个简短的code样品的所有问题。你可以使用这样的事情来验证程序集的强名称:
公共BOOL VerifyStrongName(字符串assemblyPath,布尔力)
{
如果(string.IsNullOrEmpty(assemblyPath))
抛出新的ArgumentException(的String.Empty,assemblyPath);
VAR主机= HostingInteropHelper.GetClrMetaHost< IClrMetaHost>();
VAR BUFFERSIZE = 100;
变种版本=新的StringBuilder(缓冲区大小);
VAR的结果= host.GetVersionFromFile(Assembly.GetExecutingAssembly()位置,版本,参考缓冲区大小。);
如果((HResult的)结果!= HResult.S_OK)
抛出新收到COMException(错误,结果);
IClrRuntimeInfo信息= host.GetRuntime(version.ToString(),新的GUID(IID.IClrRuntimeInfo))作为IClrRuntimeInfo;
ICLRStrongName SN = info.GetInterface(新的GUID(CLSID.ClrStrongName),新的GUID(IID.IClrStrongName))作为ICLRStrongName;
VAR verResult = sn.StrongNameSignatureVerificationEx(assemblyPath,Convert.ToByte(力));
返回Convert.ToBoolean(verResult);
}
您可以找到所有的归类与此示例中使用在 ClrActivation 示例项目的接口。
Additionaly我改变了 HRESULT 类是一个枚举...
///<总结>
///一组常见的,有用的HRESULTS和相关功能
///< /总结>
公共枚举的HResult
{
///<总结>
/// OK /真/成功
///< /总结>
S_OK = 0,
///<总结>
/// 假
///< /总结>
S_FALSE = 1,
///<总结>
///该方法未实现
///< /总结>
E_NOTIMPL =选中((INT)0x80004001)
///<总结>
///不支持接口
///< /总结>
E_NOINTERFACE =选中((INT)0x80004002)
///<总结>
///错误指针
///< /总结>
E_POINTER =选中((INT)0x8004003)
///<总结>
///一般故障HRESULT
///< /总结>
E_FAIL =选中((INT)0x8004005)
///<总结>
/// 无效的论点
///< /总结>
E_INVALIDARG =选中((INT)80070057)
///<总结>
///缓冲区不足
///< /总结>
ERROR_INSUFFICIENT_BUFFER =选中((INT)0x8007007A)
///<总结>
/// HRESULT未能找到或加载相应的运行时
///< /总结>
CLR_E_SHIM_RUNTIMELOAD =选中((INT)0x80131700)
严重性=选中((INT)为0x80000000)
}
...并添加静态归类 CLSID 和 IID (我花了一些时间来找到正确的CLSID):
公共静态类IID
{
公共常量字符串IClrRuntimeInfo =BD39D1D2-BA2F-486A-89B0-B4B0CB466891;
公共常量字符串IClrMetaHost =D332DB9E-B9B3-4125-8207-A14884F53216;
公共常量字符串IClrStrongName =9FD93CCF-3280-4391-B3A9-96E1CDE77C8D;
公共常量字符串IEnumUnknown =00000100-0000-0000-C000-000000000046;
}
公共静态类CLSID
{
公共常量字符串ClrStrongName =B79B0ACD-F5CD-409B-B5A5-A16244610B92;
}
我希望我可以帮助你。如果您还有其他问题,请不要犹豫,问。
Can anybody please suggest how to use ICLRStrongName::StrongNameSignatureVerificationEx method to identify delay signed assembly. I could not find any example in the internet. I am not understanding how to work with this method.
Please don't refer me any link, I am almost frustrated with different suggestions and different links available in the web. Can anybody please give code sample for the same.
解决方案I had the same problem and finally found the time to investigate. I really don't understand why Microsoft did not take the time to write an adequate documentation.
Following link is very helpful and also contains a sample project, even if it also doesn't answer all questions: http://clractivation.codeplex.com/
I'll try to answer all questions with a short code sample. You could use something like this to verify a assembly's strong name:
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);
}
You can find all classed and interfaces used in this sample in the ClrActivation sample project.
Additionaly I changed the HRESULT class to be an enum...
/// <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)
}
...and added the static classed CLSID and IID (took me some time to find the correct 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";
}
I hope I could help you. If you have further questions, don't hesitate to ask.