Mysterious disappearing reference

2019-02-25 09:05发布

问题:

I have what seems to be a very strange problem with a windows forms application. I am a web developer and I have limited experience of developing windows forms application. I am working on an ecommerce web site which stores product images in the database as blobs. In order to make it easier to bulk import images I am writing a small windows forms utility that uses the existing website bll library. I am using Visual studio 2010 c# and .net 4. I created a new windows forms project in my solution and added a reference to the bll project. I started coding and added using statements to my code, everything was working as expected intelisense worked corectly with my bll classes etc. Then i built the project and it failed, it complained about every line of code that refered to anything from the bll project including the using statements, and intelisense no longer worked for anything from the bll project. Basically what you would expect if there were no reference to the bll project. If i remove the reference and then re add it, or add ar reference to another projecct in the solution, intelisense comes back and all of the compiler errors disapear. Then if i build again they all reappear and intelisense no longer works.

What am i missing, what the hell might be going on here.

回答1:

Your library possibly has dependencies on other .NET libraries such as System.Web that you need to reference in your Forms app. That can create this sort of behaviour.



回答2:

I just recently had an issue like this one, and wanted to include my solution for future reference in case it comes up again. There's a warning (not an error) message that pops up when the build fails, which I missed originally because I had my error list set to filter warnings out. In my particular case I needed to change away from using the client version of .NET, and the warning message contained the information I needed to debug the problem.

Warning 44 The referenced assembly [...] could not be resolved because it has a dependency on [...] which is not in the currently targeted framework [...]. Please remove references to assemblies not in the targeted framework or consider retargeting your project. [...]"