C# type defined in an assembly that is not referenced

隐身守侯 提交于 2019-11-29 17:20:24

问题


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.


回答1:


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.




回答2:


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.



回答3:


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




回答4:


if x inherites A you must refrence it in B




回答5:


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!




回答6:


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.



来源:https://stackoverflow.com/questions/3431857/c-sharp-type-defined-in-an-assembly-that-is-not-referenced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!