Showing posts with label Errors. Show all posts
Showing posts with label Errors. Show all posts

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

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










Friday, December 27, 2019

How to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'"

In this article we review how to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'" : 405 method not allowed :




For several CORS requests, the browser sends a previous request, named "preflight request", before it sends the actual request for the resource.
It is not enought to use the standard CORS (Cross Origin Resource Sharing) on web.config , in order to solve the problem.
Here you can see the web.config settings, usually arranged to solve the problem :







How to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'" using WebApi and Angular7



The issue appears while crossing domains, and relates to POST, PUT, PATCH, and DELETE methods:
here you can see several requests , also from the Angular 7 app, as from POSTMAN :








As said, it is not enought to set the web.config to CORS.
Now,  usually the browser sends a previous request to the request that you are sending, named "preflight request", before it sends the actual request for the resource. This Preflight request is of OPTIONS type.
If the response headers do not allow the required HTTP METHOD, the browser do not send it.

The problem is, the WebApi app has not an action to process the Preflight OPTIONS request :



That is what the error is trying to say us.

So, just write an action for OPTIONS verb, that only responds an "OK", as this :



Now try again. Send a request. The breakpoint will show the OPTIONS request being processed :



Immediately after, the intended request is taken care of:





That solves this issue.
Have a good day :-)

Enjoy Angular.....

      by Carmel Schvartzman

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

Monday, July 9, 2018

WCF Error - SOLVED - Service Attribute value could not be found in ServiceHost directive


In this article we take care of the WCF Error  ' Service Attribute value could not be found in ServiceHost directive', after changing a WCF Service properties or configuration.


WCF Error - Service Attribute value could not be found in ServiceHost directive


 WCF Error - Service Attribute value could not be found in ServiceHost directive


The error is originated after you changed some properties on a WCF web service.
For example, you created a web service using a Visual Studio template, which sets a WCF service usually called "Service1".

You customized the service and, after everything seems OK, you realize that the name of the service  is inappropriate, and you change it and the class/interface behind it.
The web service stops working.
Now , the ERROR message says that the TYPE of the web service could not be found.
The clue here is that could not be found in the "ServiceHost" directive.
You take a look at the classes in your project, but can't see the Service Host:

WCF Error - Service Attribute value could not be found in ServiceHost directive

Perform a search inside your project, looking for the "ServiceHost", and add "@" to the search since we're talking about an MVC Directive:

WCF Error - Service Attribute value could not be found in ServiceHost directive
 You'll find a small HTML file with the Directive: this is the markup which enables a hosting of your web service at the development stage:


WCF Error - Service Attribute value could not be found in ServiceHost directive

As you can see, when you renamed your service, Visual Studio updated the change of the name at the CodeBehind attribute, but didn't automatically renamed the TYPE exposed by the web service, in our example "RestService" instead of "Service1":

WCF Error - Service Attribute value could not be found in ServiceHost directive

So, change the Service to the one you wish, and run it:

WCF Error - Service Attribute value could not be found in ServiceHost directive
 Now you get it in JSON WebMessageFormat. If you wanted XML, just don't set any ResponseFormat, and you'll get the XML default format for WCF web services:

WCF Error - Service Attribute value could not be found in ServiceHost directive

WCF Error - Service Attribute value could not be found in ServiceHost directive



That's all!!!!


By Carmel Shvartzman

עריכה: כרמל שוורצמן

Thursday, June 11, 2015

How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'

In this post we describe Step by step how to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'.  
This HTTP Error is sent back in the response by a web service following to an HTTP Ajax Request. This is a CORS (Cross Origin Resource Sharing) error, because it's originated by the different domains of the web Referer (the Requesting URL) and the Web Service (the Requested URL).
Frequently this error looks like this:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'



Step by step how to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'



The internet web tool that we're using in this tutorial is the Chrome's Developer Tool (F12).
Normally, in the case of an status 200 (OK) response, we would have the following HTTP Headers at the "Network" tab, meaning that the HTTP request has been accepted:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'    1


As you notice , both URLs ( requested- requesting URLs) belong to the same Domain ("http://localhost:XXXX/"):
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'   2


No problem here.

However, in our case, we probably got some Error like the following:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'     3



If you open the Headers tab, and take a look at the URLs of both Referer and web service, you'll notice the following:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'    4




You can note that they are different domains: we have a CORS (Cross Origin Resources Sharing) problem here. The browser has sent an HTTP OPTIONS request to the service, asking it whether it will accept an HTTP DELETE request, by using the Access-Control-Request-Method header.
Now here at the Response Headers, we see that the Access-Control-Request-Method header do not include the HTTP DELETE method, which is therefore not allowed:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'   5




Usually, CORS problems are issued because the Access-Control-Request-Origin do not accept Ajax requests from Domains other than its own domain.
Here the CORS problem is about the HTTP Method being used.
To fix it, you must be allowed access to the Web Service's  web.config file , where the "httpProtocols" are located:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'     6




Once there, first check that the allowed origins are all domains ( "*" ).
Next, add to the Access-Control-Request-Method the one you need: HTTP DELETE in our case:

Step by step how to fix the Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'     7

Save the web.config file, and send the Request again:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'    8



This time, the HTTP OPTIONS returns an status 200 (OK), informing to your browser  that the "DELETE" request is indeed allowed:
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'      9




Now is up to the browser to send the HTTP DELETE request, and this time, the response get status 200 (OK) :
How to fix the CORS Error 'Method DELETE is not allowed by Access-Control-Allow-Methods'     11





We hope that this post has helped you ..

Happy programming.....

      by Carmel Schvartzman


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

Monday, April 27, 2015

How to Fix the OptimisticConcurrencyException in MVC

In this post we describe Step by step How to Fix the OptimisticConcurrencyException in MVC.  
We take care here in just 5 minutes of the errors raised by the Entity Framework while the EDM (Entity Data Model) is confronting a database concurrency issue.

In short, when two or more users try to modify data simultaneously , SQL offers two types of Concurrency Control:
1) Pessimistic Concurrency : lock the data table in advance because someone for sure will try to   affect your changes simultaneously. Action to perform: LOCK the table!
2) Optimistic Concurrency : make your changes and let's hope none will try to alter the record in the meantime. Action to perform: raise an error if the record was altered in the meantime!

Our approach here will be: if indeed the record was altered from the original (AKA the "OptimisticConcurrencyException" was thrown), then we'll refresh the data and save your important updates with a "Client Wins" policy.


How to Fix the OptimisticConcurrencyException in MVC


To apply our approach, we'll use here a "Save(object itemToSave, int #noOfItemsToSave )" method, wrapping the context's SaveChanges().
We just add here a "catch" block to the C# method which tries to update an item to the database.
This way we enforce refreshing the item and saving all your changes overriding the refreshed data.
Therefore, add the following method to your Data Repository (copy-paste:) :

public bool Save(object target, int RecordsNumber)
        {
            try
            {
                return Context.SaveChanges() == RecordsNumber;
            }
            catch (OptimisticConcurrencyException)
            {
                ObjectContext ctx = ((IObjectContextAdapter)Context).ObjectContext;
                ctx.Refresh(RefreshMode.ClientWins, target);
                return Context.SaveChanges() == RecordsNumber;
            }
        }


As you see, the return value tells that all edited items have been successfully persisted to database.
Then you can use this method from your MVC Controller as follows:


 [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Blog blog)
        {
            if (ModelState.IsValid)
            {
                db.Update<Blog>(blog);
                db.Save(blog, 1);
                return RedirectToAction("Index");
            }
            ViewBag.BloggerID = new SelectList(db.Retrieve<Blogger>(null), "BloggerID", "Name", blog.BloggerID);
            return View(blog);
        }








Happy programming.....

      by Carmel Schvartzman


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




Monday, April 20, 2015

Error 8 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapODataServiceRoute'


In this article we fix the Error 8 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapODataServiceRoute', while adding a route to an ASP.NET application containing an OData Web API.



 System.Web.Http.HttpConfiguration MapODataServiceRoute


The error is originated after the Microsoft decision to create a new assembly to support the v4.0 version of the OData protocol, but keeping the OLD assembly which supported the version 3.0. The resultant side by side scenario where applications can reference to v3.0 and v4.0 simultaneously, can be the source of errors as the one we're fixing here. 
May be one of the more important changes here is , the "QueryableAttribute"  has now been renamed "EnableQueryAttribute". You can explore the assemblies differences in this MSDN article.

The new OData v4.0 assembly is "System.Web.OData" instead of the OLD "System.Web.Http.OData" , and the new package is called "Microsoft.AspNet.OData".

So the error appears after you configure the OData Endpoint at the WebApiConfig  Register()  :

Error  8 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapODataServiceRoute'

public static void Register(HttpConfiguration config)
        {
            
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Note>("Notes");
            config.MapODataServiceRoute(
                routeName: "ODataRoute",
                routePrefix: "OData",
                model: builder.GetEdmModel());          

        }

The "routePrefix" sets the name of the Service Endpoint.

When you compile, you receive the following error message:



Because the Extension Methods in the new OData v4.0 assembly were moved to "System.Web.OData.Extensions", and the method "MapODataRoute" has been renamed to "MapODataServiceRoute", we must reference to that extensions namespace.
Therefore go to the usings section up in your C# file, and add the Extensions namespace to allow the use of the extension method that we are supposed to use:



using System.Web.Http.OData;
using System.Web.OData.Builder;
using System.Web.Http;
using System.Web.OData.Extensions;



That's all!!!!


By Carmel Shvartzman

עריכה: כרמל שוורצמן

Tuesday, February 3, 2015

How to fix the Visual Studio 2012 Error 'An incompatible DacFx version is installed'

In this article we see How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'.

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'



 How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'


This error is originated in Visual Studio 2012 , when trying to open a database on the
Server Explorer , clicking the "Show table Data" :


How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 1



How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 2


The solution for the problem is installing the SSDT - Sql Server Data Tools for Visual Studio 2012 : the SSDT is a tool to make easy for programmers to edit database objects and data, to execute queries, or to perform database design from within the Visual Studio environment.



How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 3

Browse to the Microsoft Data Developer Center and download the SSDT :

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 4


After the download, run the install file as Administrator:

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 5

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 6

Restart the Visual Studio 2012 and try again to perform some edit to a database:

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 7


This time you could open the table designers or edit the table's data:


How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 8

That's all!!!!


By Carmel Shvartzman

עריכה: כרמל שוורצמן