Friday, January 14, 2022

SOLVED - Error "The build failed" - "An error occurred in the tool" on Microsoft WCF Web Service Reference Provider

 In this tutorial we'll learn how to fix the error "The build failed" - "An error occurred in the tool" on Microsoft WCF Web Service Reference Provider.  

We'll use the  Microsoft WCF Web Service Reference Provider tool for refreshing endpoints data on a  WCF application .
Every time something changes on  the service, the consumer application has to refresh its Connected Services references.
However, the following error could happen without previous record, avoiding you to refresh the WCF references:  





Step by step how to fix the error "The build failed" - "An error occurred in the tool" on Microsoft WCF Web Service Reference Provider


You want to refresh the WCF service reference on your project, as follows:


But you are confronted with the following error:


The error message "The build failed" could be misunderstood: my project is building correctly, hence, what is failing to build?

The WCF Web Service Reference Provider tool  creates two projects in a temp folder, and these projects are the ones failing to build.
These projects are stored in the following folder:
%localappdata%\Temp\WCFConnectedService

Opening the folder corresponding to the current time and date, check the bootstrapper project, opening it with Visual Studio:



After you open the project, try to build it. You will get the following errors:



Indeed, this is the project which "The build failed".
Opening the project Properties, you see that there is not "Target Framework" asigned to the project:



After you select from the list the correponding target framework, try to recompile it, to see that this time the build has succeded.

And this gives us a hint of what happened here: because of an internal bug of the tool inside Visual Studio, the correct framework has been mismatched.
To see this clearly, open the folder of your project on Explorer, and type "CMD" on the address. The command line interface CLI  - (a.k.a. CMD Prompt window) , will open.
Then type :
dotnet --version

This will tell you what is the version of Dotnet being used.
And you'll see that is not the same version used by your project.

The problem here is, the WCF tool is using the global dotnet version , instead of the framework used by your project.
Probably, after the creation of your project, you have installed additional .NET SDKs, and now the tool is taking the latest of them into account, instead of the one corresponding to your project.

To fix this, change the dotnet version used by the tool , as follows:

1) Type on the CLI this command, which will allow you to see all dotnet sdks installed on your machine:
     dotnet --info

Select the one matching the framework used by your project.

2) On the same command line interface that you opened before, (i.e. the folder of your project), type the following in order to change the version locally:
dotnet new globaljson --sdk-version X.X.XXX  ( for example : 2.2.110)

Where X.X.XXX is the version that you selected before.

3) Type again dotnet --version, to see the changes.

4) Run again the WCF Web Service Reference Provider tool. This time your references will be refreshed accordingly.

You can try another solution, which is to update your Visual Studio to the latest version, hoping that the issue had been resolved. It will cost you a download of about 4 GIGABYTE of data.
However, the above solution will be straightforward and painless.

That's all.... 
In this tutorial we've seen how to fix the error "The build failed" - "An error occurred in the tool" on Microsoft WCF Web Service Reference Provider. 
Happy programming.....


      By Carmel Shvartzman
כתב: כרמל שוורצמן



No comments:

Post a Comment