This is a weird one.
I created a new Windows Service in C#, and want to re-use some of the code we created before that's in a Class Library.
The project is loaded in the solution along with the service. Both target .NET Framework 4.0 (not client profile).
I tried adding a project reference, and it worked for a short while. After working on some old code that I was rewriting, when the project compiled again, it complained that it no longer recognised the namespace for the using statement.
I've made sure to clean the solution & rebuild, but no dice. Sometimes VS can have a bad day, 开发者_StackOverflow社区so I restarted VS, but this also didn't work.
I then build the DLL, and add a reference to it via 'browse', also no dice. Then I tested it on another project, but after adding it, it works instantly, so it's not the DLL.
I then checked with other libraries in the solution, but I was able to add a reference to them in the service and access their namespace without a problem.
I'm out of ideas here, anyone got an idea of what to do here?
Thanks,
Nick.
Almoast forgot: the weird thing is, that if I open up the Class view, and expand the 'References' section, the namespace/dll doesn't show up there either... it's a real conundrom...
I should pay more attention to warnings:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3253: The referenced assembly "" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
So, I'm a ready idiot for checking the DLL's target framework but not the Windows Service :)
The problem is my DLL uses System.Web, which is not part of the .NET 4 Client Profile framework target. Changing the Service's Target Framework to 4.0 fixed it.
If the class view doesnt show the types that should be there, the actual dll you're compliling against is not the correct version.
There could be several reasons for this
- A previous compilation of the dll might still be around
- The project might reference another, older, binary version of the library rather than having a project reference
- Another project mgiht be referencing an old version of the dll, and have copy local set to
true
. When that project is compiled it overwrites the new version of the library
Make sure all projects in the solution use project references, and remove all binaries you can find.
精彩评论