5 Debugging Tips for a Solution that Won’t Compile

Home / 5 Debugging Tips for a Solution that Won’t Compile

One of the first things a developer is asked to do when starting on a new project is to download the code and get the software running. Far too often, that code will not run, or even compile, without specific steps that are known only by the original developer(s). But what if the original developer isn’t available to assist with the necessary computer configurations, build steps, or 3rd party installations to get a new development environment up and running? These debugging tips represent a proactive strategy to independently resolve a code base that is fraught with compile errors.

(Examples represent debugging in C# .NET and Visual Studio 2013)

Free User-Friendly Software Checklist

The_user-friendly_software_checklist_-_provided_by_unstoppable_software_pdf__page_1_of_4_

In the last ten years, we've created hundreds of SUPER user-friendly applications that our customers LOVE to use. Our secret? We follow these 7 simple guidelines. Sign up to receive your FREE copy of our checklist now.

Powered by ConvertKit

 

Build One Project at a Time

One small compile error in the right project can cause numerous errors across the solution. We must isolate our efforts to the projects that are actually causing the problem. To do this, compile each project individually and see which are already working.

 

 

Fix Independent Projects First

Because compile errors cascade through to other projects that depend on the problematic code, we should work on those projects that are independent of others first. One way to determine those projects is to look at the project references and make sure it is not pointing to any of the other projects in this solution.

 

 

Right-click on References and click Add Reference. This opens the Reference Manager. This image shows other projects are unchecked, so this project is independent of the others.

Note: Visual Studio Ultimate Edition has a feature under the Architecture tab called “Generate Dependency Graph For Solution” that makes this easy. However, this only works if the solution already compiles.

 

Investigate Reference Paths

One of the two most common reasons why a project cannot compile is because a referenced library cannot be found. Either the file is simply missing from the source code or Visual Studio cannot resolve the path to it.

 

 

To troubleshoot this situation (you can see that the missing library has a yellow triangle icon), edit the .csproj file directly. Right-click on the project and choose Unload Project. Right-click the project again and choose Edit.

 

 

The xml for the .csproj file will load into the text editor. Search for the project reference that cannot be resolved. It is quite possible that the file exists in the source code, but a relative path has been configured that is different on the original developer’s machine. Take a look at the file path and make sure the file exists where the path points. If the path is inaccurate, either move the library or alter the .csproj file.

 

 

Search for 3rd Party Libraries

When a referenced library is not part of the source code, it might be downloadable from the Internet. Try Googling the name of the missing project to see if the library is commonly used and available. The NuGet Package Manager is part of Visual Studio and is another great source of .NET libraries.

 

 

Lastly, try to gain read access to the deployment directories of this application on the network. For example, it is possible that missing libraries are in the bin directory of the production source code.

 

Obtain Missing Source Code

The other most common reason why a project cannot compile is because a source file is missing or out of date. The easiest way to debug this .NET code is to contact the previous developer. The file is likely sitting on his or her computer waiting to be committed to source control. Unfortunately, if this is not an option, desperate (i.e. time-consuming) options are all that remain:

  • Try looking through the source control history log. Perhaps the file was once there but has been accidentally deleted or changed.
  • Go back to the production server files and see if the file exists there. If not, go a step further and decompile production code. Perhaps the decompiled code can be inserted into the development code to resolve class or logic dependencies.

Follow the above tips to tackle a non-compiling Visual Studio solution. Hopefully, these ideas aid your debugging in C# and revive an otherwise overwhelming code base.

Nathan Stuller
Nathan Stuller

Nathan Stuller is Development Manager and Lead Developer at Unstoppable. He enjoys problem solving for big companies, working in new technologies, and driving our projects to successful completion.

Recommended Posts
Showing 2 comments
  • Nathan
    Reply
    This is good for when the code in source control doesn't compile, but it also got me thinking there are ways to prevent that situation from happening.
    
    One of the best ways to validate the code in source control is to perform automated builds. By ensuring that new code commits compile (and pass tests), it will be more likely that new developers get good complete code.
    
    If a build machine is not an option, you can test to make sure what you committed will build by renaming your solution folder, redownloading the source code, and trying to compile. Since this gets a fresh version of the code from the repository, it can at least serve as an ad hoc sanity check that the code is complete.
    
  • Sam Schutte
    Reply

    Good point – some good example automated/unattended build servers out there are:

    – CruiseControl.NET: http://www.cruisecontrolnet.org

    – Jenkins: http://jenkins-ci.org

    – Microsoft Team Foundation Server: http://www.visualstudio.com/products/tfs-overview-vs

Leave a Comment

Start typing and press Enter to search

Top IT Consulting Firmscustom software development in ohio