Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

c# - Random assembly references fail ("Are you missing a using directive or an assembly reference?")

My application has a mixture of 3.5 and 4.0-targeted assemblies. I'm working on a new Windows service targeting 4.0 and the project suddenly seems unable to see some of the other assemblies in the solution. Meaning, on build, all references to these certain other assemblies produce the following error:

The type or namespace name '[X]' does not exist in the namespace '[Y]' (are you missing an assembly reference?)

If I delete the project reference and re-add it, the red squigglies go away and Intellisense kicks in again like it's supposed to. All of the other projects in the solution build without issue. But as soon as I try to build this new project, the errors come back.

One of the failing references is to our Core.dll, which targets 3.5. We recently added a CoreEx.dll targeting 4.0, with namespace sharing between the assemblies. The new service can see CoreEx.dll but not Core.dll... i.e., when I begin typing using Core.Utilities... Intellisense picks up on the smaller set of namespaces from CoreEx.dll but does not show any that appear only in Core.dll. I'm pretty sure the solution built successfully after adding this, but it's a notable recent change.

Another failing reference is to our core Data.dll which holds a bunch of datasets and Entity Framework stuff. This one was recently migrated to 4.0. Again, I'm almost positive the solution built after migrating the project, but it's worth mentioning.

The last failing reference is an assembly that uses the namespace one level "up" from the service. E.g., the problematic project is based out of namespace ProductName.Component.ComponentService and it is unable to see the project based out of namespace ProductName.Component. This one was recently created along with the problematic project and also targets 4.0.

As you can see, there doesn't seem to be any rhyme or reason to which assembly references are failing... and the problematic project can successfully reference some of the other assemblies in the solution. I've tried cleaning, re-building, restarting Visual Studio... nothing has fixed it permanently. What could be causing this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check the target platform of the new project and make sure it's not targeting .NET 4 Client Profile. If it is, change it to regular .NET 4


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...