Could not load file after another project updated package versions - asp.net-core

We have 2 projects hosted on IIS: Blazor WebAssembly site and authorization web service.
Web service is hosted on Default Web Site, Blazor project as a separate site. Each has it's own app pool ('No managed code'). Both are .NET6 using EF Core. They do not reference each other.
Recently I updated packages in Blazor project to latest versions. After publishing that change our web serivce started throwing:
An unhandled exception has occurred while executing the request.
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Abstractions, Version=6.0.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.EntityFrameworkCore.Abstractions, Version=6.0.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder..cctor()
EntityFrameworkCore libraries on that web serivce are of version 6.0.5. Our Blazor site was moved to 6.0.6. How can one affect the other?
They are both published by Jenkins as self-contained without trimming, then copied to server.
Web service does not reference Microsoft.EntityFrameworkCore.Abstractions directly, but I can see it down the line of package refences for EF Core.
I can see the relevant library in the physical folder on server, it's of expected version 6.0.5.
Still, web server throws on any GET, with Swagger or via the Blazor site.
Tried so far:
Add rights for IIS_IUSRS for site and service folders
Changing app pool identity for web service
Add rights for app pool specific users for site and service folders
Enabling 32-bit app setting in IIS, it is not compatible with our apps
Checked that ASPNET user has rights to Temp folder just in case
The issue still occurs, on some days it all works without problems.

There are many reasons for this error, you can try below methods:
Restart the server to reload everything again, check if site works.
Change 'Enable 32-bit application' from false to true in the advanced settings of the application pool.
Change the identity of the AppPool that your app is using to NetworkService.
IIS > Application Pools > Select current app pool > Advance Settings > Identity.
Grant IIS_IUSRS full access to the Microsoft.EntityFrameworkCore.Abstractions.

Setting hosting model as OutOfProcess for the web service finally fixed the issue. Other solutions did not provide any lasting results.
It can be set in web.config:
<aspNetCore ... hostingModel="outofprocess">

Related

Can I run .Net 4.6 Application under .Net Core Site on IIS

I inherited a project that is a collection of WCF Services that target .Net Framework 4.6.1. I wrote a front end SPA application that targets .Net Core 2.2 not realizing that the hosting model was such that both the UI (.Net Core) and the API (.Net 4.6.1) need to run under one Site on IIS.
I'm trying to get this to work on my local machine. I created a new Site in IIS -- Site A. I published my .Net Core application to Site A and set it up with an application pool set to "No Manged Code".
I then added an Application to Site A called API and added all my WCF services in that folder. I configured API to use an application pool that targets ".NET CLR 4.0".
I updated the web.config in the root of Site A to include all the necessary bits for WCF.
I'm able to hit Site A and get my SPA UI, but when I do anything that attempts to hit the backend API (including trying to hit it directly -- http://localhost:464646/api/test.svc), I get the following error:
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
Is what I'm doing even possible? If so, what changes do I need to make in order to get this to work?

Get HTTP 500 error hosting ASP.Net Core MVC app in IIS

I am new to ASP.Net Core and trying to host my first simple MVC app in IIS. I have installed the IIS hosting bundle; published my MVC project to a folder using Visual Studio and then, created an IIS website with it's physical path set to the published folder. When I test it using url http://localhost:5008/home/CallApi, however, I am getting a 500 error that says "This page isn’t working. localhost is currently unable to handle this request.". I can run the MVC app from within VS (selfhost, not through IIS, on a different port), it works fine there. What am I doing wrong here?
If you want to deploy ASP.Net Core MVC applications to IIS, you need to install the .NET Core host bundle, otherwise "500 Error" will appear. If you successfully install the .NET Core host bundle, you can find AspNetCoreModuleV2 in Modules:
Download the installer using the following link:
https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer
After adding the site, you need set the .NET CLR version to No Managed Code:
For more information about using IIS to host ASP.NET Core on Windows, you can refer to this link:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1
UPDATE:
I suggest you enable viewing of PII logs so that we can view more detailed information about the error:
public void ConfigureServices(IServiceCollection services)
{
IdentityModelEventSource.ShowPII = true;
....
You can refer to this link, which contains similar questions:
"InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'"
For those with the same issue, I found that no setup guide I found mentions what was, for me, a required step:
Open IIS Manager
Navigate to [Server]\Sites[Your site]. A folder is listed for your .NET application, but the icon shows as an ordinary folder, as if in Windows Explorer.
Right-click the folder and select, "Convert to Application".

NetCore API Impersonate

I have a Web and an API NetCore Application running in a machine that I have access by VPN.
There, in IIS, I've configured both applications in IIS: The Web and the API. They are running well.
At the API, I've tryied to open the file from a network path:
\10.50.20.24\g$\Buffer\821003\003\22\34\821003003223428.WAV
In my code, when I try to verify if the file exists, using System.IO.File, to after move it, I received a message saying that the file doesn't exists.
"file was not found"
But the file exists, and the file is there when I try to access it from Windows Explorer.
In the IIS, I've configured the same user to run the application, in the Identity of the application pool.
I've tried lots of things to try to access the file, unsuccessfully.
Do you think this is related to Impersonation? How could I implement Impersonation in Asp.Net Core API 3.1 ?

ASP.NET WebAPI deployed to IIS: Access to web.config denied (IIS searches in wrong path)

I have an ASP.NET MVC/WebAPI mixed project which runs just fine in the VS2012 development server. It has a standard MVC {controller}/{action}/{id} route, as well as an additional WebAPI route api/{controller}/{id}. Requests which start with /api/... are directed to WebAPI, the others to normal MVC.
When I deploy it to the local IIS, the normal MVC routes are working. However, /api calls to WebAPI are resulting in the exception
Access to the path 'C:\inetpub\wwwroot\myapp\web.config' is denied.
Then I tried to set the proper security permissions on the inetpub folder and its subfolders. This didn't help anything, and because the normal MVC requests are working, I don't suspect the problem to be security-related.
Then I started Sysinternals Process Monitor to see what w3wp.exe is doing during the request. As it turns out, IIS looks for web.config here:
C:\inetpub\wwwroot\myapp\api\web.config
C:\inetpub\wwwroot\myapp\api\mycontroller\web.config
Of course, there is no web.config there.
How can I set up IIS to recognize both routes?
I do not believe this is a problem with your routing. the problem is the permissions given to IIS I run into this error from time to time. Depending on the app pool identity you are running under you need to provide permissions to that entity. Here is a link to a very thorough explanation
IIS AppPoolIdentity and file system write access permissions
Basically right click your project folder, go to properties, click the security tab and and you will see Group or user names. These are the allowed entities to perform read and/or write actions to that directory. Click Edit then Add; from here you will then "Enter the object names to select" typically IIS follows under IIS_IUSRS again this depends on your app pool configuration from here you should move on from the error mentioned!
I hope this helps!

Identity Check Issues in IIS Hosted WCF Service

I have a set of WCF Services Hosted in IIS7. I'm in the process of moving the services to a different folder in order to start specifying version and environment in the URL. For example:
http://myserver/MyServices/ServiceA.svc
Becomes:
http://myserver/MyServices/QA/1.1.0/ServiceA.svc
I configured the new folder to be an application in IIS, and set it up to run under the same service app pool we've been using. That has all worked fine, I am able to navigate to my .svc URL and view the WSDL or open up the endpoint in wcf test client. However, when trying to consume the service I am getting the following error:
The identity check failed for the outgoing message. The expected identity is 'identity(http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn)' for the 'http://myserver/MyServices/QA/1.1.0/ServiceA.svc' target endpoint.
When I check the WSDL output, I noticed that the identity section seemed to leave out the identity of the app pool, which it usually includes:
<Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<Upn>myappuser#mydomain.local</Upn>
</Identity>
After trying to redeploy and reconfigure the app in IIS, I was able to get the identity to appear in the metadata for only some of the services. Other services still don't include it, which is even more strange than before. There are zero configuration differences between the original stack and the new stack in IIS as far as I can tell. What sorts of issues could I be running in to that would causes these types of identity issues?
The issue was caused by trying to nest the new service stack web application inside of the existing service stack web application. I think that may have caused some confusion for IIS when services in the sub-application were exposing endpoints to the same contracts that the root web application (although in theory this should work just fine). I simply had to move the new service stack into a separate folder structure. Once I did that, I had no problems getting the app pool identity to be exposed in the metadata.