2

Everytime I build my solution I get the following warning:

Warning Could not resolve this reference. Could not locate the assembly "WordAPI". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. OfferteHost

However everything seems to work just fine, it's only a warning, but it's bugging me.

How did it start?

I renamed one of the projects in my solution. Used the right click -> rename option. I also used search and replace to rename the namespace for all my files in the project. Changed the AssemblyInfo.cs file. In my project properties on the application tab I changed the Assembly Name and Default Namespace. I'm also using Costura.Fody if it would matter.

How did I try to fix it?

  • I changed the HintPath in the project file of my executing assembly:

    <HintPath>..\WordAPI\bin\Debug\WordAPI.dll</HintPath>
    
  • Removed the reference from my executing assembly and readded it.
  • Deleted my debug/release folders across the solution and rebuilt the solution

I really can't find the solution, it's tempting to start a blank solution and just copy everything in there...


The properties of my reference:

enter image description here

Location of the project in file explorer:

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Alexander Derck
  • 13,818
  • 5
  • 54
  • 76
  • Tried to kill .suo file inside your build-folder? – EngineerSpock Jan 27 '16 at 08:49
  • 2
    Put `WordAPI.dll` into some folder of your project (e.g. "Library") and reference it from there (delete old reference and add new, this time pointing dll from "Library"). Don't use `obj` and `bin` folder ever to reference anything. – Sinatr Jan 27 '16 at 08:52
  • @EngineerSpock Just delete it and rebuild? Sintatr I will do that once it's finished, but right now I'm changing both projects at the same time so I won't copy the .dll everytime I make a change. – Alexander Derck Jan 27 '16 at 08:53
  • Is WordAPI.dll also created dynamically, then you may need to correct the build order of projects. WordAPI.dll should be created first. – Anil Jan 27 '16 at 08:54
  • @AnilKumar Where can I choose the build order? If I remove all debug folders (so all dll's are removed) I can build the solution though, so it seems fine – Alexander Derck Jan 27 '16 at 08:57
  • Solution right click-> Project Build Order, here you can set dependency also. – Anil Jan 27 '16 at 08:59
  • If `wordAPI` is one of your project, then ignore my previous comment. Add this project to solution, reference **project** (not dll-file), setup build order. If you renamed `wordAPI` project, then you may simply have to re-reference it. If you renamed some other project, which is referencing `wordAPI`, then nothing is normally needed. – Sinatr Jan 27 '16 at 08:59
  • @Sinatr The build order is correct. `WordAPI` is on top, `OfferteHost` on the bottom. Like I said in my question, I already removed the reference and readded it, deleted the dll's and rebuilt them etc. It's very odd – Alexander Derck Jan 27 '16 at 09:04
  • Try BUILD->Batch Build->Select All and then press "Clean". After that make sure that you are referencing WordAPI.dll from some external folder. – Andriy Buday Jan 27 '16 at 09:19
  • @AndriyBuday Thanks but as I said referencing from an external folder is not an option. I'm still designing the application and I can't manually copy the library everytime I make a small change. Eventually when it's finished I will copy the library to my executing assembly. – Alexander Derck Jan 27 '16 at 09:22

3 Answers3

2

Assuming that WordAPI is in the same solution as your executable, the reference should not use HintPath. Remove and add reference using Solution -> Projects selection. The reference in the executable csproj should look like:

<ProjectReference Include="..\WordAPI.csproj">
  <Project>{GUID}</Project>
  <Name>WordAPI</Name>
</ProjectReference>

As was said in the comments, HintPath should not point to Debug directory since the same path is used for Debug and Release build configurations, which might be the source of your problem.

Without more details about your projects, solution, build paths, build configurations, it is hard to give better answer.

  • This did it! Proves once again the best solution is a simple solution :D The `HintPath` is indeed removed from my OfferteHost.csproj file. – Alexander Derck Jan 27 '16 at 09:31
1
  1. The Path should not point to the /bin folder. Instead, you might want to reference the /packages folder in the
  2. The 'Copy Local' property in the Reference properties should be 'True', so the referenced .dll file is actually copied while deploying the application.
webMac
  • 185
  • 1
  • 2
  • 11
  • 1
    This is ultimately the solution, but my question was regarding the development phase when you don't want to manually copy your dll's every time you make a change. – Alexander Derck May 31 '17 at 09:54
0

Assuming you have the Assembly project and the test project (executable) in the same solution, you have to go on the property pages of the Solution, then "Common properties" > "Project Dependencies", then select your test project in the "Projects" combobox, and check "Depends on" checkbox of your assembly project. So now your assembly will be built before starting building the test executable and the warning will disappear. Otherwise building would be concurrent and the assembly might not exist yet while starting building the test executable.

This works for VS2015 at least.

BillyJoe
  • 878
  • 7
  • 25