无法获取 StrongNameKeyPair 的公钥

发布于 2024-11-01 09:17:24 字数 647 浏览 1 评论 0原文

我已将开发移植到另一台计算机,如果我运行项目,则会出现以下异常:

无法获取 StrongNameKeyPair 的公钥。

HibernateException:创建代理实例失败

在原始计算机上它可以正常工作,没有问题。

我在谷歌上发现一些加密存在问题,我应该尝试“sn -m n”,但我不知道如何。 sn.exe 位于更多文件夹中,我尝试从命令行运行一些,但它写道:

无法打开注册表项 -- 无法格式化错误消息 00000005

我不知道问题是否是因为 NHibernate,还有更多类似的对话框,并且仅在一种情况下抛出此异常。

有部分代码会抛出异常:

public IList<DTO> GetAll(GridSortOptions sortOptions, DTOListModel<DTO> listModel)
{
    return GetAllCriteria(sortOptions, CreateCriteria(), listModel).List<DTO>();
}

解决方案中没有一个项目使用签名。 我不明白这个错误到底意味着什么以及我应该寻找什么。

I have ported developing to another computer and if i run project, i have this exception:

Unable to obtain public key for StrongNameKeyPair.

HibernateException: Creating a proxy instance failed

On original computer it works OK without problems.

I found on google that it is problem with some crypting and I should try "sn -m n", by I don't know how. sn.exe is in more folders, i tryed some run from command line but it writes:

Failed to open registry key -- Unable to format error message 00000005

I don't know if problem is because NHibernate or not, there are more similar whitch dialogs and it throw this exception only in one case.

there is part of code whitch throw exception:

public IList<DTO> GetAll(GridSortOptions sortOptions, DTOListModel<DTO> listModel)
{
    return GetAllCriteria(sortOptions, CreateCriteria(), listModel).List<DTO>();
}

No one project from solution use signing.
I don't understand what exactly this errors means and what i should look for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

全部不再 2024-11-08 09:17:24

NHibernate 正在动态创建 .NET 程序集(动态代理)并需要对它们进行签名。默认情况下,Windows 操作系统将加密密钥存储配置为计算机级别,并将密钥存储在 C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys 中。您的用户很可能可以在此文件夹中创建(例如)文本文件,但不能删除它,因为您没有完全控制权。

您的选项是

  1. 通过修改可能不建议的权限来完全控制 C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys。

  2. 通过运行 Windows SDK 中的“sn.exe -m n”将加密密钥存储更改为用户级别。 http://msdn.microsoft.com/en- us/library/k5b5tt23(v=VS.90).aspx 这会将加密密钥存储放在您的用户本地配置文件下,您应该始终对其拥有完全控制权。

网上有几篇文章描述了类似的问题。例如,请参阅 http://support.targetprocess.com/Default.aspx ?g=posts&t=305

NHibernate is dynamically creating .NET assemblies (dynaic proxies) and needs to sign them. By default the Windows OS configures the crypto key storage to be machine level and stores the keys in C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys. Most likely your user can create (for example) a text file in this folder, but not delete it because you do not have full control.

Your options are

  1. Get full control of C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys by modifying permissions which might not be recommended.

  2. Change your crypto key storage to user level by running the "sn.exe -m n" from the Windows SDK. http://msdn.microsoft.com/en-us/library/k5b5tt23(v=VS.90).aspx This will put crypto key stores under under your users local profile which you should always have full contorl to.

There are several articles online that describe a similar problem. For example, see http://support.targetprocess.com/Default.aspx?g=posts&t=305.

相权↑美人 2024-11-08 09:17:24

今天在不同的用例(在 W2008R2 机器上运行的 .NET 服务)中遇到了类似的问题,但出现了完全相同的错误。

使用 procmon,我将其追溯到 C:/ProgramData/Microsoft/Crypto/RSA/MachineKeys 中的密钥写入失败。

按照此处所述的指南添加对文件夹具有特殊权限的所有人解决了问题:http://toastergremlin.com /?p=432

另外,请确保添加 EVERYONE @ 本地计算机,而不是 EVERYONE @ 您的域!

Had a similar issue today with a different use case (a .NET service running on a W2008R2 box) but exactly the same error.

Using procmon I traced it back to a failed write on a key in C:/ProgramData/Microsoft/Crypto/RSA/MachineKeys.

Following the guidance to add EVERYONE with special permissions on the folder as noted here fixed the problem: http://toastergremlin.com/?p=432

Also, make sure you add EVERYONE @ local machine and not EVERYONE @ your domain!

眼眸里的快感 2024-11-08 09:17:24

对于遇到此问题的其他人来说,我在物理机器上也遇到了同样的例外。一夜之间什么都没有改变,但这个异常从早上开始出现。

结果是磁盘空间不足的问题,动态代理程序集无法写入磁盘。只是意识到这一点是因为我碰巧注意到 Windows“磁盘空间不足”图标短暂出现。 :-P

清除一堆(大)临时文件使问题消失。

For anyone else who comes across this, I just had the same exception, on a physical machine. Nothing changed overnight, but this exception started presenting in the morning.

Turned out to be low disk space issue, and the dynamic proxy assemblies couldn't be written to disk. Only realised this because I happened to notice the Windows 'low disk space' icon when it appeared briefly. :-P

Clearing out a bunch of (big) temp files made the problem go away.

独﹏钓一江月 2024-11-08 09:17:24

我今天遇到了同样的问题,并且不喜欢所提供的解决方案。它们是:

  • 拥有您自己的 Castle.Core 版本,并删除了强命名代码。 参考
  • 修改文件夹的权限。参考:这个问题
  • 更改加密密钥存储。参考:这个问题

下面可能是一个肮脏的黑客,但它工作得很好,我不需要向 IT 解释为什么我希望所有最终用户计算机重新配置。

/// <summary>
/// Ensures that NHibernate creates no strong named proxy assemblies.
/// Assumes usage of Castle.DynamicProxy. Needs to be revisited
/// after update of NHibernate or Castle.Proxy!
/// </summary>
private static void EnsureNHibernateCreatesNoStrongNamedProxyAssemblies()
{
    if (!StrongNameUtil.CanStrongNameAssembly)
    {
        Logger.Debug("NHibernate is not trying to strong name assemblies." +
                     "No action needed.");
        return;
    }

    const string FieldName = "canStrongNameAssembly";
    var type = typeof(StrongNameUtil);
    var field = type.GetField(FieldName, BindingFlags.Static
                                         | BindingFlags.NonPublic);
    if (field == null)
    {
        Logger.Warn(
            "No field with the name {0} exists in the type {1}."
            + "Can't change NHibernate to use weak named proxy assemblies.", 
            FieldName, type);
        return;
    }

    field.SetValue(null, false);

    if (StrongNameUtil.CanStrongNameAssembly)
    {
        Logger.Warn(
            "Couldn't change value of field {0} on type {1}. "
            + "NHibernate will continue to use strong named proxy assemblies.", 
            FieldName, type);
    }
    else
        Logger.Debug("Successfully changed NHibernate to use "
                     + "weak named proxy assemblies.");
}

只需确保在生成第一个代理之前在程序的最开始调用此方法即可。

我想真正的解决方案是升级到 NHibernate 3.3,它应该不再有这个问题,但现在这不是一个选择。

I had the same issue today and didn't like the provided solutions. These were:

  • Having your own version of Castle.Core with the strong naming code removed. Reference
  • Modifying permissions on the folder. Reference: This question
  • Changing the crypto key storage. Reference: This question

The following may be a dirty hack but it works quite well and I don't have to explain to IT why I want all of the end users computers reconfigured.

/// <summary>
/// Ensures that NHibernate creates no strong named proxy assemblies.
/// Assumes usage of Castle.DynamicProxy. Needs to be revisited
/// after update of NHibernate or Castle.Proxy!
/// </summary>
private static void EnsureNHibernateCreatesNoStrongNamedProxyAssemblies()
{
    if (!StrongNameUtil.CanStrongNameAssembly)
    {
        Logger.Debug("NHibernate is not trying to strong name assemblies." +
                     "No action needed.");
        return;
    }

    const string FieldName = "canStrongNameAssembly";
    var type = typeof(StrongNameUtil);
    var field = type.GetField(FieldName, BindingFlags.Static
                                         | BindingFlags.NonPublic);
    if (field == null)
    {
        Logger.Warn(
            "No field with the name {0} exists in the type {1}."
            + "Can't change NHibernate to use weak named proxy assemblies.", 
            FieldName, type);
        return;
    }

    field.SetValue(null, false);

    if (StrongNameUtil.CanStrongNameAssembly)
    {
        Logger.Warn(
            "Couldn't change value of field {0} on type {1}. "
            + "NHibernate will continue to use strong named proxy assemblies.", 
            FieldName, type);
    }
    else
        Logger.Debug("Successfully changed NHibernate to use "
                     + "weak named proxy assemblies.");
}

Just make sure you call this method at the very beginning of your program before the first proxy is generated.

I guess the real solution would be to upgrade to NHibernate 3.3 which suppesdly doesn't have this problem anymore, but that's not an option right now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文