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 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:
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.
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:
- Open RegEdit on Your Computer
- Access this registry key: Computer \ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSBuild \ ToolsVersions \ 4.0
- 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.
- Open this registry key and see which directory of the SDK files
- Now open the directory under the “InstallationFolder” key in Windows Explorer. As expected, the sgen.exe executable is not in that directory.
- 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.
- After copying the file, you can now normally compile your project in Visual Studio.
Thanks for stopping by and see you in the next post.