在未引用的程序集中定义的 C# 类型

发布于 2024-09-13 11:36:06 字数 558 浏览 5 评论 0原文

我有两个项目 A 和 B。项目 A 在项目 B 中使用了类型 X,因此我在 A 中添加了对 B 的引用。一切都构建得很好。

我使用强命名密钥文件签署了项目 B。一切仍然建立得很好。

然后我决定更改 B 的强命名密钥文件。我重新构建了项目 B ok。当我尝试构建项目 AI 时,收到错误“错误 1 ​​类型 X 在未引用的程序集中定义。您必须添加对程序集 B、Version=1.0.0.0、Culture=neutral、PublicKeyToken=95b41b0d6571627b 的引用”。 “

所以我删除了项目 A 中的引用,然后再次将其添加回来,很不高兴。我可以双击项目 A 中的项目 B 引用,打开对象浏览器,然后在其中查看类型 X 即可。我还完全限定了 A 中的类型 X 对象,并且智能感知很好地拾取了它们,但它仍然无法构建。

我认为更改密钥文件可能需要升级版本,因此我将程序集 B 版本更改为 2.0.0.0,但 A 仍然抱怨它需要版本 1.0.0.0。查看 A 中 B 引用的属性,它肯定指向正确的版本,实际上它显示为 2.0.0.0

我可以接受使用现有的密钥文件,但如果可能的话,我想了解我哪里出错了。

I have two projects A and B. Project A makes use of type X in project B, so I have a reference to B added in A. Everything built fine.

I signed project B using a strong named key file. Everything still built fine.

Then I decided to change the strong named key file for B. I rebuilt project B ok. When I try to build project A I receive the error "Error 1 The type X is defined in an assembly that is not referenced. You must add a reference to assembly B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=95b41b0d6571627b'. "

So I deleted the reference in project A and added it back in again, no joy. I can dbl click on the project B reference in project A, open the object browser and see type X in there ok. I also fully qualified the type X objects in A and the intellisense picked them up fine but it still does not build.

I thought that changing the key file I might need to up the revision, so I changed assembly B version to 2.0.0.0 but still A complains that it needs version 1.0.0.0. Looking at the properties of the B reference in A it definitely points to the correct version and indeed it shows as 2.0.0.0

I could live with using the existing key file but i'd like to understand where I am going wrong if possible.

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

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

发布评论

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

评论(7

姐不稀罕 2024-09-20 11:36:07

根据您在评论中所说的内容,我想说这绝对是项目 A 的问题。

也许这些步骤将有助于修复它:

  1. 删除对项目 B 的引用并保存
  2. Crack 使用记事本或其他工具打开 .csproj 文件
  3. 查找任何内容引用其中的项目 B(可能是提示路径节点)并删除该节点。
  4. 如果项目 A 恰好是 ASP.NET 项目,请在 web.config 或 aspx 页面标头中查找对项目 B 的任何引用。

删除对项目的所有引用后,按照瓶颈建议重新加载项目,看看是否可以修复给你的。

Based on what you said in the comments, I would say it's most definitely something up with Project A.

Perhaps these steps will help fix it:

  1. Remove the reference to project B and save
  2. Crack open the .csproj file with notepad or something
  3. Look for any references to Project B in there (maybe a hintpath node) and remove the node.
  4. If Project A happens to be an ASP.NET project, look in your web.config or your aspx page headers for any references to Project B.

Once you remove all references to the project, reload the project as bottlenecked suggested and see if that fixes it for you.

忆梦 2024-09-20 11:36:07

抱歉回答晚了,但这对我有帮助:(

假设您当前有 AnyCPU 解决方案平台)

  • 将解决方案平台切换到 x86。
  • 编译
  • 切换回
  • 再次编译。

Sorry for late answer, but this helped me:

(Assuming that you have AnyCPU solution platform currently)

  • switch solution platform to x86.
  • compile
  • switch back
  • compile again.
冷…雨湿花 2024-09-20 11:36:07

对我有用的是删除对项目的引用,然后再次将其添加回来。出现一条新的错误消息,指出我需要对缺少的第三个库的引用,因此原始消息有点误导!

What worked for me was to remove the reference to the project, then add it back in again. A new error message appeared stating that I needed a reference to a third library that was missing, so the original message was a bit misleading!

梦在夏天 2024-09-20 11:36:07

这也发生在我身上。

就我而言,问题在于解决方案 AI 引用了解决方案 B 中的项目(我更改了 B 中的项目名称)。当我尝试编译A时,它试图在B中找到项目的旧名称。

我再次添加了该项目的新引用,重新编译等等,但不幸的是它不起作用。

当我在 A 中再次添加 B 的所有引用时,问题得到解决。我正在加载用 B 的旧项目编译的旧 DLL。这些 DLL 与旧引用有某种交叉交互。

我希望这对其他人有用。

This also happened to me.

In my case, the problem was that from a solution A I was referencing projects from a solution B (I changed the name of a project from B). When I tried to compile A, it tried to find the old name of the project in B.

I added again the new reference of this project, recompile and so on but unhopefully it did not work.

The problem was fixed when I added again all the reference of B in A. I was loading old DLLs that were compiled with the old project of B. These DLLs had some kind of cross interaction with the old reference.

I hope this work for someone else.

下壹個目標 2024-09-20 11:36:07

您可以尝试编辑项目 A 的项目文件 (projectA.csproj)。要通过 Visual Studio 右键单击​​项目 -> 卸载项目,然后在卸载的项目上右键单击 -> 编辑文件来执行此操作。在那里搜索对项目 B 的引用,并尝试根据需要进行更正

You could try editing the project A's project file (projectA.csproj). To do this through visual studio right click on the project->unload project and then on the unloaded project right click->edit file. Search for the reference to project B in there, and try to correct as necessary

川水往事 2024-09-20 11:36:07

为了帮助人们从 Google 到达这里, Merlyn 的评论询问延迟签名是我的答案。

我在引用延迟签名的程序集 A 时遇到此错误,该程序集引用了程序集 B 中定义的类型 X。我收到的错误是未引用 B(并且我已经在引用 B 的签名版本)。

修复方法是查找并引用 A 的签名版本。

To help people getting here from Google, Merlyn's comment asking about delay-signed was the answer for me.

I was getting this error referencing a delay-signed assembly A that referenced a type X defined in assembly B. I got the error that B wasn't referenced (and I was already referencing the signed version of B).

The fix was to find and reference the signed version of A.

眼角的笑意。 2024-09-20 11:36:07

如果 x 继承 A 你必须在 B 中引用它

if x inherites A you must refrence it in B

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