简体   繁体   English

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

[英]C# type defined in an assembly that is not referenced

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.我有两个项目 A 和 B。项目 A 在项目 B 中使用类型 X,所以我在 A 中添加了对 B 的引用。一切都很好。

I signed project B using a strong named key file.我使用强命名密钥文件签署了项目 B。 Everything still built fine.一切仍然很好。

Then I decided to change the strong named key file for B. I rebuilt project B ok.然后我决定更改 B 的强命名密钥文件。我重建了项目 B ok。 When I try to build project AI 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'. "当我尝试构建项目 AI 时收到错误“错误 1 ​​类型 X 在未引用的程序集中定义。您必须添加对程序集 B 的引用,版本=1.0.0.0,文化=中性,PublicKeyToken=95b41b0d6571627b”。 ”

So I deleted the reference in project A and added it back in again, no joy.所以我删除了项目 A 中的引用并重新添加了它,不高兴。 I can dbl click on the project B reference in project A, open the object browser and see type X in there ok.我可以 dbl 单击项目 A 中的项目 B 引用,打开对象浏览器并在那里看到类型 X 确定。 I also fully qualified the type X objects in A and the intellisense picked them up fine but it still does not build.我还完全限定了 A 中的 X 型对象,并且智能感知很好地拾取了它们,但它仍然无法构建。

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.我认为更改密钥文件可能需要进行修订,因此我将程序集 B 版本更改为 2.0.0.0,但 A 仍然抱怨它需要版本 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查看 A 中 B 引用的属性,它肯定指向正确的版本,并且确实显示为 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.我可以忍受使用现有的密钥文件,但如果可能的话,我想了解我哪里出错了。

Based on what you said in the comments, I would say it's most definitely something up with Project A.根据您在评论中所说的,我会说这绝对是项目 A 的问题。

Perhaps these steps will help fix it:也许这些步骤将有助于解决它:

  1. Remove the reference to project B and save删除对项目 B 的引用并保存
  2. Crack open the .csproj file with notepad or something用记事本或其他东西破解打开 .csproj 文件
  3. Look for any references to Project B in there (maybe a hintpath node) and remove the node.在那里查找对项目 B 的任何引用(可能是一个提示路径节点)并删除该节点。
  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.如果项目 A 恰好是 ASP.NET 项目,请查看您的 web.config 或 aspx 页头以查找对项目 B 的任何引用。

Once you remove all references to the project, reload the project as bottlenecked suggested and see if that fixes it for you.删除对项目的所有引用后,按照瓶颈建议重新加载项目,看看是否能解决问题。

Sorry for late answer, but this helped me:抱歉回复晚了,但这对我有帮助:

(Assuming that you have AnyCPU solution platform currently) (假设您目前有 AnyCPU 解决方案平台)

  • switch solution platform to x86.将解决方案平台切换到 x86。
  • compile编译
  • switch back切换回来
  • compile again.再次编译。

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!出现了一条新的错误消息,指出我需要引用缺少的第三个库,因此原始消息有点误导!

To help people getting here from Google, Merlyn's comment asking about delay-signed was the answer for me.为了帮助人们从 Google 到达这里, Merlyn关于延迟签名的评论是我的答案。

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).我在引用延迟签名的程序集 A 时遇到此错误,该程序集 A 引用了程序集 B 中定义的类型 X。我收到了未引用 B 的错误(我已经在引用 B 的签名版本)。

The fix was to find and reference the signed version of A.解决方法是找到并引用 A 的签名版本。

You could try editing the project A's project file (projectA.csproj).您可以尝试编辑项目 A 的项目文件 (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.为此,请通过 Visual Studio 右键单击​​项目-> 卸载项目,然后右键单击已卸载的项目-> 编辑文件。 Search for the reference to project B in there, and try to correct as necessary在那里搜索对项目 B 的引用,并根据需要尝试更正

This also happened to me.这也发生在我身上。

In my case, the problem was that from a solution AI was referencing projects from a solution B (I changed the name of a project from B).就我而言,问题在于解决方案 AI 引用了解决方案 B 中的项目(我从 B 更改了项目名称)。 When I tried to compile A, it tried to find the old name of the project in B.当我尝试编译 A 时,它试图在 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.当我再次在 A 中添加 B 的所有引用时,问题得到解决。我正在加载用 B 的旧项目编译的旧 DLL。这些 DLL 与旧引用有某种交叉交互。

I hope this work for someone else.我希望这对其他人有用。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c# 类型在未引用的程序集中定义 - c# The type is defined in an assembly that is not referenced CS0012 C#类型“ HttpContext”在未引用的程序集中定义 - CS0012 C# The type 'HttpContext' is defined in an assembly that is not referenced C#-引用类型'ISomeInterface'在未引用的程序集中定义 - C# - The reference type 'ISomeInterface' is defined in an assembly that is not referenced 在未引用的程序集中定义类型“ x”。 VS 2010 C# - The type “x” is defined in an assembly that is not referenced. VS 2010 C# C#出现错误:在未引用的程序集中未定义类型“ Indirect.Class”。 必须添加对程序集“间接”的引用 - C# Getting Error: Type “Indirect.Class” Not Defined In an Assembly Not Referenced . Must Add a reference to assembly “Indirect” 该类型在未引用的程序集中定义 - The type is defined in an assembly that is not referenced 该类型在未引用的程序集中定义。 c#,通用存储库模式,URF - The type is defined in an assembly that is not referenced. c#, Generic Repository Pattern, URF 类型“ MailAddress”在未引用的程序集中定义 - The type 'MailAddress' is defined in an assembly that is not referenced “DateTime”类型是在未引用的程序集中定义的? - The type 'DateTime' is defined in an assembly that is not referenced? 在未引用的程序集中定义了“电子邮件”类型 - The type 'EMail' is defined in an assembly that is not referenced
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM