在 Visual Studio 2008 中编译程序时出错

发布于 2024-07-14 10:38:37 字数 819 浏览 10 评论 0 原文

所以我以前从未见过这个问题,也不知道从哪里开始解决这个问题。

Cannot register assembly "obj\Debug\MyProject.Vsto.dll".
Loading this assembly would produce a different grant set from other instances. 
(Exception from HRESULT: 0x80131401)  

我从哪里开始解决这个问题?

我应该提到这是一个带有 VS2008 SP1 的 VS2008 环境,这个解决方案是:
1. VSTO Excel 2007 项目(C#)
2. 数据访问/服务层 DLL (C#)
3. #2 (C#) 的 MbUnit 测试项目

更新: 我应该补充一点,这几个月来效果很好。 上周左右我唯一改变的是我开始通过 Team Foundation Server (TFS) 编写代码。

更新2: 删除 .suo 文件暂时有效。 现在我又遇到同样的错误......嗯。 我想我会关闭项目并再次删除 .suo

更新3: VS2008 将允许我编译一次解决方案。 我第二次尝试时收到错误。 如果我退出,删除.suo文件,然后重新打开我可以再次编译一次。 对原因有什么想法吗? 这是VS2008 SP1的事情吗?

对于赏金,我正在寻找永久的解决方案。

So I have never seen this issue before and don't know where to begin troubleshooting the issue.

Cannot register assembly "obj\Debug\MyProject.Vsto.dll".
Loading this assembly would produce a different grant set from other instances. 
(Exception from HRESULT: 0x80131401)  

Where do I start to troubleshoot this?

I should mention this is a VS2008 environment with VS2008 SP1 and this solution is:
1. A VSTO Excel 2007 Project (C#)
2. A Data Access / Service Layer DLL (C#)
3. An MbUnit test project for #2 (C#)

UPDATE:
I should add this did work fine for several months. The only thing that I have changed in the last week or so is I have started working on the code via Team Foundation Server (TFS).

UPDATE 2:
Deleting the .suo file worked for a little while. Now I'm getting same error again.... hmmm. Guess I'll close the project delete the .suo again.

UPDATE 3:
VS2008 will allow me to compile the solution once. The second time I try I get the error.
If I exit, delete the .suo file, and reopen I can compile one time again. Any thoughts to the cause? Is this an VS2008 SP1 thing?

For the bounty I'm looking for the permanent solution.

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

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

发布评论

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

评论(8

月亮坠入山谷 2024-07-21 10:38:37

仅供参考...看起来像 CLR HRESULT (中间的 13 表示这一点)。
根据此博客文章:很多HRESULT代码...具体的HRESULT是
SECURITY_E_INCOMPATIBLE_SHARE 0x80131401 -2146233343

最有可能的是某个错误的进程在程序集上持有一个打开的句柄,并阻止编译器放置新的句柄。 鉴于更新#3,该进程可能是 devenv.exe ...这对于缩小范围没有帮助,但它可能是一些随 VS 关闭的后台进程(例如调试器托管进程)。

假设文件中存在某些内容...要调试此类内容,第一步是从 SysInternals 工具集。 在其中您可以使用“查找”来确定哪个进程打开了该文件的句柄。 当您遇到此问题时,我希望它会显示 devenv.exe 中打开的句柄。

在 procexp 中,您可以执行关闭句柄这一高度危险的操作。 之后,在不关闭的情况下再次尝试这些步骤。 如果问题没有重现,那么您就知道您关闭的句柄是问题的原因。 如果其他事情顺利的话……那个“高度危险”的步骤可能就是原因。

如果您知道哪个进程有打开的句柄,那么您需要看看是否可以防止它遇到句柄的明显泄漏。 我会检查项目设置...包括复制文件的任何内容的调试设置。 如果有一个名为 VSHosting 进程的调试器设置...将其关闭。

祝你好运。

Just FYI ... that looks like a CLR HRESULT (the 13 in the middle indicates that).
Acording to this blog post:A lot of HRESULT codes... That specific HRESULT is
SECURITY_E_INCOMPATIBLE_SHARE 0x80131401 -2146233343

Most likely some errant process is holding an open handle on the assembly and preventing the compiler from laying down a new one. Given update #3 that process is probably devenv.exe ... which is unhelpful in narrowing it down, however it could be some background process which shuts down with VS (such as the debugger hosting process).

Assuming something is holding on the file ... to debug this type of thing the first step is to open procexp.exe from SysInternals toolset. In it you can use Find to determine which process has a handle open to the file. I'd expect it to show a handle open within devenv.exe when you hit this issue.

From within procexp you can do the highly dangerous thing of closing the handle. After that try the steps again without shutting down. If the problem doesn't repro then you know the handle you closed was the cause of the problem. If anything else happens well ... that 'highly dangerous' step was likely the cause.

If you know what process has the open handle then you need to see if you can prevent it from hitting the apparent leak of the handle. I would check the project settings ... including the debug ones for anything that copies the files. If there is a debugger setting called VSHosting process ... turn that off.

Good luck.

驱逐舰岛风号 2024-07-21 10:38:37

我做了一些谷歌搜索,发现 MSDN 论坛上的这篇文章可能对您有用(也可能没有)。

它提到了一些应该安装的 Windows 更新补丁(如果您使用的是 Vista)以及解决方法(如果您使用的是 XP)。 尽管该帖子提到了 Silverlight 的问题...错误是相同的,所以也许?

祝你好运!

I did some Googling and found this post on MSDN Forums which may (or may not) prove useful to you.

It mentions a few Windows Updates patches that should be installed (if you're on Vista) as well as a workaround if you're on XP. Although the post is referring to problems with Silverlight... the error is the same, so maybe?

Good luck!

本王不退位尔等都是臣 2024-07-21 10:38:37

我还没有看到确切的错误,但如果有从不同位置加载的 DLL 的另一个副本,则可能会发生类似的错误。

我会搜索一下是否还有该 DLL 的其他副本

dir MyProject.*.dll /s

I haven't seen that exact error, but similar errors can occur if there's another copy of the DLL that gets loaded from a different location.

I'd do a search to see if there's any other copies of that DLL lying around

dir MyProject.*.dll /s
顾铮苏瑾 2024-07-21 10:38:37

那么它创建了 dll 但之后不喜欢使用它? 如果是这种情况,您是否尝试在 Reflector 中打开 dll,看看第一次编译和第二次编译之间可能存在哪些差异?

另一个想法 - 在第一次成功构建后您是否尝试过清理/重建? 您是否在每次编译时更新版本号? 我想知道是否引用了过时的文件,但在第一次编译后进行了更新。 此时参考文献与预期不符。

另一个随机的想法 - .suo 文件通常包含与您的个人计算机相关的信息。 与编译相关的内容不应保存在该文件中 - 它应该保存到 .sln 中。 .suo 是根本原因似乎很奇怪......

So it creates the dll but doesn't like to use it afterward? If that's the case, have you tried to open the dlls in Reflector to see what differences there might be between the first and second compilation?

Another thought - have you tried a clean/rebuild after the first successful build? Are you updating the version numbers on each compile? I'm wondering if an outdated file is being referenced, but updated after the first compile. At which point the references don't match the expected ones.

Another random thought - the .suo file generally contains info related to your individual machine. Something related to the compilation shouldn't be saved in that file - it should go to the .sln instead. It would seem odd that the .suo is the root cause...

披肩女神 2024-07-21 10:38:37

看来你开发了一个 ms-office 扩展。 然后您应该安装最新的COM Shim Wizard。 VS2008 的下载是 这里

托管 Office 扩展应相互隔离。 MSDN 上的这篇文章解释了为什么以及如何。

我假设您的 .dll 不是隔离的,因此您会得到“Security-share-error”:

隔离。如果您不使用
标准 COM 垫片(例如 Visual
Office 加载程序的 Studio 工具)或
提供您自己的自定义 COM 垫片,您的
扩展DLL加载到默认的
应用程序域以及所有
其他未加垫片的延伸件。 所有 DLL
在同一个应用程序域中运行
容易受到潜在损害
由同一DLL中的任何其他DLL引起
应用领域。 另外,任何
未填充的加载项会崩溃
主机应用程序禁用所有其他
未填充的插件
应用程序。

开发 Office 扩展一开始看起来很简单,但后来....

Thomas

seems that you develop an ms - office extension. Then you should install the latest COM Shim Wizard. Download for VS2008 is here.

Managed Office extensions should be isolated from each other. This article on MSDN explains why and how.

I assume that your .dll is not isolated, and therefore your get that "Security-share-error":

Isolation. If you do not use a
standard COM shim (such as the Visual
Studio Tools for Office loader) or
provide your own custom COM shim, your
extension DLL loads into the default
application domain along with all
other un-shimmed extensions. All DLLs
running in the same application domain
are vulnerable to potential damage
caused by any other DLL in the same
application domain. Also, any
un-shimmed add-in that crashes in a
host application disables all other
un-shimmed add-ins for that
application.

Developing office extensions looks so simple at the beginning, but then ....

Thomas

邮友 2024-07-21 10:38:37

我看过这个 线程 这似乎突出了一些类似的问题。

如何排除故障? 我想说首先检查您的应用程序是否可以生成此类错误消息。 然后检查您的软件所依赖的库或系统是否可能有故障(然后寻求支持或社区支持)。

祝你好运。

I have seen this thread which seems to highlight some similars issues.

how to troubleshoot? I would say first check that if your application could generate this kind of error message. Then checked if the libraries or system your software relies on could be faulty (then ask for support or community support).

Good luck.

简美 2024-07-21 10:38:37

这有点超出了我的范围,但我确实找到了以下 链接,该链接表明您在 .net 2.0 中遇到了已知缺陷

我从微软建议的解决方法中复制了以下内容:

编组时会出现问题
值介于两者之间的对象
应用程序域在同一进程中
实例的类型是通用的,
定义了通用模板类型
在 mscorlib 中,它的一个或多个
实例化类型未定义在
mscorlib 和多域加载器
优化已在其中启用
域,但不是另一个域。

不幸的是这个错误被发现了
太晚了,没能进入酒吧
V2.0产品。 有一些
但是解决方法:

此错误特定于优化的
进程中的版本,
跨应用程序域远程处理通道和
因此可以通过切换来避免
这种优化关闭了流程。
这可以通过设置来实现
以下环境变量
在命令窗口中进行测试
将被执行:

设置 complus_UseNewCrossDomainRemoting=0 
  

或者通过设置
HKEY_CURRENT_USER\Software\Microsoft.NETFramework\UseNewCrossDomainRemoting
注册表值(DWORD)为 0(或
HKEY_LOCAL_MACHINE 中的版本)。

这些有点重量级,但它是
也有可能欺骗优化
避免特定的路径
转移有问题的电话
目的。 为此,添加一个虚拟输出
调用的参数(对于各种
技术原因 优化路径
尚未实现输出参数)。

您还可以避免使用 mscorlib
定义的泛型类型。 在重现中
所呈现的案例很简单
因为你可以只输入 List 的子类型:

<前><代码>[可序列化]
公共类 MyList; : 列表
{
}

(只需将 List 的所有使用替换为
我的列表)。

最后,这个问题应该不会发生了
如果两个应用程序域都使用
多域优化。 你不能
设置默认域的加载程序
优化之后你已经
运行它,但你可以设置它
外部(我相信通过
非托管托管 API 或配置
文件,虽然我不是这方面的专家
要么,对不起)或者通过创建一个新的
域(具有多域选项)内
您的代码并将控制权转移到
它(通过调用 MBRO 对象
该域)。

很抱歉,如果您已经在搜索中找到了这篇文章,但我没有看到这里提供它作为解决方案。

This is a little outside my area but I did find the following link which suggests that you are encountering a known defect with .net 2.0.

I copied the following from the suggested work-around from microsoft:

The problem will occur when marshaling
an object by value between two
appdomains in the same process where
the type of the instance is generic,
the generic template type is defined
in mscorlib, one or more of its
instantiating types is not defined in
mscorlib and multi-domain loader
optimization has been enabled in one
domain but not the other.

Unfortunately this bug was discovered
too late and didn't make the bar for
the V2.0 product. There are some
workarounds however:

This bug is specific to an optimized
version of the in-process,
cross-appdomain remoting channel and
therefore can be avoided by switching
this optimization off for the process.
This can be achieved either by setting
the the following environment variable
in the command window where the test
will be executed:

set complus_UseNewCrossDomainRemoting=0

Or by setting the
HKEY_CURRENT_USER\Software\Microsoft.NETFramework\UseNewCrossDomainRemoting
registry value (a DWORD) to 0 (or the
version in HKEY_LOCAL_MACHINE).

These are a bit heavyweight, but it's
also possible to fool the optimized
path into avoiding just the specific
call that transfers the problematic
object. To do this add a dummy out
parameter to the call (for various
technical reasons the optimized path
doesn't implement out parameters yet).

You can also avoid using an mscorlib
defined generic type. In the repro
case presented this is simple enough
since you can just subtype List:

[Serializable]
public class MyList<T> : List<T>
{
}

(Just replace all uses of List with
MyList).

Finally, the problem shouldn't occur
if both appdomains are using the
multi-domain optimization. You can't
set the default domain's loader
optimization after you're already
running it but you can either set it
externally (I believe via the
unmanaged hosting API or a config
file, though I'm not an expert in
either, sorry) or by creating a new
domain (with multi-domain opt) within
your code and transferring control to
it (via a call on an MBRO object in
that domain).

Sorry if you've already found this article in your searching but I didn't see it offered here as a solution.

止于盛夏 2024-07-21 10:38:37

你不会弄乱系统时间吧? 这样做可能会弄乱你的程序集。

You're not messing with the system time are you? Doing that can mess up your assemblies.

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