Showing posts with label DotNet Core. Show all posts
Showing posts with label DotNet Core. Show all posts

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
כתב: כרמל שוורצמן



Wednesday, September 2, 2020

SOLVED - IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies"

 In this tutorial we'll learn how to solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies"  

This error ocurrs while deploying an Asp.Net Core app to IIS .

First of all, search for the ERROR CODE on the Troubleshoot ASP.NET Core  :



Step by step how to  solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies" 

You'll find there that the .NET Core runtime in-process fails to start. OK.

So may be the Microsoft.NETCore.App or Microsoft.AspNetCore.App runtime isn't installed?

Check the "Modules" tab on your app on IIS . 

However, the Modules are there :



The cause stated at the troubleshoot, is that the version does not exists on the machine:




So, search for the download link on the following url :  Publish an ASP.NET Core app to IIS



Below the title "Install the .NET Core Hosting Bundle" , you'll find the download link :  

Current .NET Core Hosting Bundle installer (direct download)



Download it, and copy it to the machine where the IIS is installed:

Run it as Administrator, and RESTART IIS after the setup is finished (my website >>> STOP >>> START (or RECICLE)) :


That's all.... 
In this tutorial we've seen how to  solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies. 
Happy programming.....
      By Carmel Shvartzman

כתב: כרמל שוורצמן










Wednesday, May 20, 2020

Step by step how to add custom headers using Asp.Net Core 3.0

In this tutorial we'll learn   how to add custom headers using Asp.Net Core 3.0 
We'll use Postman for testing purposes of a RESTful WEBAPI Core application, sending  HTTP POST requests. We'll start with a WebApi Core 3.0 application,  and we'll add an Extension Method to the Response class in order to append our headers.
See the code here:
https://github.com/CarmelSchvartzman/DOTNET/blob/master/HEADERS/ADD_HEADERS_EXTENSIONMETHOD





Step by step how to add custom headers using Asp.Net Core 3.0



First, we create a new Extension Method to the Response class in order to append our headers., in Visual Studio, as follows:





  public static class Extensions
    {
        public static void AddApplicationError(this HttpResponse response, string msg)
        {
            response.Headers.Add("Carmel-Error", msg);
            response.Headers.Add("Access-Control-Expose-Headers", "Carmel-Error");
            response.Headers.Add("Access-Control-Allow-Origin", "*");
        }

    }

On the startup.cs file , we add to  the Configure method , the following code:

  if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(b => {
                    b.Run(async ctx => {
                        ctx.Response.StatusCode = (int) 
HttpStatusCode.InternalServerError;
                        var err = ctx.Features.Get<IExceptionHandlerFeature>();
                        if (err != null)
                        {
                            ctx.Response.AddApplicationError(err.Error.Message);
                            await  ctx.Response.WriteAsync(err.Error.Message);
                        }
                         
                    });
                });
            }

This code catchs all exceptions globally, and also adds our headers to the response.
Send a request using Postman, and open the "headers" window to see them:












That's all.... 
In this tutorial we've seen  how to add custom headers using Asp.Net Core 3.0  
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן