在未引用的程序集中定义的 C# 类型
我有两个项目 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据您在评论中所说的内容,我想说这绝对是项目 A 的问题。
也许这些步骤将有助于修复它:
删除对项目的所有引用后,按照瓶颈建议重新加载项目,看看是否可以修复给你的。
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:
Once you remove all references to the project, reload the project as bottlenecked suggested and see if that fixes it for you.
抱歉回答晚了,但这对我有帮助:(
假设您当前有 AnyCPU 解决方案平台)
Sorry for late answer, but this helped me:
(Assuming that you have AnyCPU solution platform currently)
对我有用的是删除对项目的引用,然后再次将其添加回来。出现一条新的错误消息,指出我需要对缺少的第三个库的引用,因此原始消息有点误导!
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!
这也发生在我身上。
就我而言,问题在于解决方案 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.
您可以尝试编辑项目 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
为了帮助人们从 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.
如果 x 继承 A 你必须在 B 中引用它
if x inherites A you must refrence it in B