Click on the banner to learn about and purchase my database training on Azure

Visual Studio - Resolving the problem between sgen.exe and the .NET Framework SDK (Build Error)

Views: 2.171 views
Reading Time: 3 minutes

Hello people,
Good afternoon!

In this post I will share with you an issue I had while developing some CLR routines in C # in a new build environment using VMware, Windows 7 x64, and Visual Studio 2015 Community Edition.

The problem

The problem occurs when I try to build or publish my assembly to the database. This type of problem is not unique to CLR, but rather to Visual Studio + .NET Framework, affecting C # developers as well.

The error message that occurs is this:

Microsoft Visual Studio 2015 - SdkToolsPath Build Error

Task could not find “sgen.exe” using the SdkToolsPath “” or the registry key “HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SDKs \ Windows \ v8.0A \ WinSDK-NetFx40Tools-x86”. Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed

It is very clear that what is happening is that Visual Studio cannot find the sgen.exe executable. Let's understand the reason.

The solution - Solving the problem

Doing a quick search on Google, I identified some “solutions” pointed out by users:

  • Install Visual Studio 2010: I think going back in time and using Visual Studio 2010 is not cool. Mainly because in VS 2010 I can't even publish the CLR to a SQL Server 2014 database.
  • Install the Windows SDK: It might even be a possible solution, but the SDK is not available for all platforms, such as Windows Server 2012, for example, so it would not be a definitive solution.
  • Disable serialization assembly generation: I have tested this solution and it really works. The error no longer occurs.

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix - Disable Serialization Assembly

    However, as I use WebServices and XML serialization, it is not an option for me, since if I do not generate the serializer my project will have runtime errors.

Well, since none of them seemed to be a solid solution, let's look for a new alternative. Analyzing some more answers and publications, I was able to identify this way to definitively solve the problem:

  1. Open RegEdit on Your Computer
  2. Access this registry key: Computer \ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSBuild \ ToolsVersions \ 4.0

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 1

  3. Note that the key SDK40ToolsPath points to another registry key, which is where the files really are located. If you are using the .NET Framework 2.0 or 3.5 in your project, you should look at the SDK35ToolsPath key.
  4. Open this registry key and see which directory of the SDK files

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 2

  5. Now open the directory under the “InstallationFolder” key in Windows Explorer. As expected, the sgen.exe executable is not in that directory.

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 3

  6. Go into the folder of another SDK that has this file, copy the executable and paste it back into this folder. I believe that since the executable is stand-alone (it has no dependencies), it can be any version. I suggest always getting the latest version, respecting the macro version of the platform.

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 4

  7. After copying the file, you can now normally compile your project in Visual Studio.

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 5

    Microsoft Visual Studio 2015 - SdkToolsPath Error Fix 6

Thanks for stopping by and see you in the next post.