How to get shutdown reason in .NET Core 3.1 Azure Web App - asp.net-core-3.1

Is there an equivalent to .NET Framework's HostingEnvironment.ShutdownReason in .NET Core 3.1? How can I get a meaningful shutdown reason for my Azure hosted web application PRIOR to shutdown?
I am looking for something like that:
// this code is called when the web app stops
private void OnShutdown()
{
myCustomLogger.LogAppShutdown(HostingEnvironment.ShutdownReason);
}

Related

DLL creating a connection fails with "An existing connection was forcibly closed by the remote host"

I have created a DLL [made available as a NuGet package (.NetStandard 2.0/2.1)].
When a particular class in this DLL is instantiated, we fire an synchronous GET call to a .Net Core WebAPI installed on IIS on my local machine (localhost) to load some configuration data.
This DLL makes use of a singleton HttpClient (we've following Microsoft's 'best practices' here)
Factory.SingletonHttpClient().GetAsync(args.Uri).GetAwaiter().GetResult();
I've consumed this NuGet package in a whole series of applications, all built using .Net Framework 4.7.2 and they work just fine - the data is successfully retrieved from the WebAPI.
However....I have one particular application (again, 4.7.2) where the GET consistently fails with the error message:
System.Net.Sockets.SocketException HResult=0x80004005 Message=An
existing connection was forcibly closed by the remote host
This exception was originally thrown at this call stack:
System.Net.Sockets.Socket.BeginReceive(byte[], int, int, System.Net.Sockets.SocketFlags, System.AsyncCallback, object)
So this has to be something specific to my application that consumes this NuGet package since it works for all other consuming applications. However, I can't see how to figure out what the problem might be.
So I found the answer, but I'm confused by it.
I'm using the latest version of Windows 10 (version 1909).
All my applications are using .Net 4.7.2
So when I debug all these .NET 4.7.2 applications on my machine, they all make the call to the WebAPI on my IIS LocalHost, except this one application.
When I look at the ServicePointManager.SecurityProtocol in this failing application, I see it's running with the obsolete values of SSL and TLS. Why would this be the case for this application but not the others? It's not stipulated anywhere to use these obsolete protocols, so why is this using them but not the other applications?
I fixed this by amending my NuGet DLL to add TLS1.2 to whatever TLS versions are being used:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | ServicePointManager.SecurityProtocol;

Consume a SOAP Service in an Azure function

Environment
Visual Studio 2017 Enterprise on MAC, Mono 5.12.0.309
Problem
I've successfully built and packaged an Azure Function. Now, I'd like to call a SOAP Web service in the function (over which I have no control). I added a Web Reference to the published WSDL and tried to compile the function which resulted in a ton of errors primarily indicating "System.Web.Services" namespace is missing.
"System.Web" doesn't seem to be part of .NET Core 2.1 (that is referenced in the function project). How would I then add a reference to "System.Web.Services" assembly? Is there a NuGet package?
UPDATE
Part of this was my lack of understanding of what .NET Core actually is. Since I'm using .NET Core, I can't make reference to assemblies that are targeting .NET Framework. "System.Web.Services" seems to be one.
Now the question becomes, how one would then call SOAP Services from .NET Core application?
You can use the new WCF client side stack on .NET Core: https://github.com/dotnet/wcf
There is a good sample to a question on this thread: Calling a SOAP service in .net Core

How to make ASP.NET Core RC1 work with the GA SDK?

The previous non-GA versions of Service Fabric came with support (and template) for ASP.NET Core RC1. GA removed this support.
I have a project that depends on ASP.NET Core RC1. I would also like to update to the new SDK now.
I can get the asp.net service to run with the latest SDK without any significant changes to code. However creating a ActorProxy or ServiceProxy in the asp.net project fails with exception "The config package was not found". So my asp.net service is unable to communicate with the rest of the services in the application.
How can i fix the issue with ActorProxy and ServiceProxy on ASP.NET Core RC1 service?
Someone else discussed the same problem in the comments of Service Fabric documentation. Vaclav came up with workaround to the bug. Basically the client project requires ConfigurationPackage named "Config". Projects based on the old ASP.NET Core template didn't have the ConfigurationPackage.
For details of implementing the workaround, see:
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-get-started/#comment-2601127160

.NET Framework Method Not Found 'Void System.GC.Collect'

I'm trying to run some service and I'm getting this message
Method not found: 'Void System.GC.Collect(Int32,
System.GCCollectionMode)'
I suspect the server because this service runs on other servers.
I really want to know what the source of this problem because I came across this problem on other servers.
I try to take of code from my service and finally I realized that even I run a console application with only one static main and call the GC I get this error,
I'm using Windows Server 2003 with Framework 2.0 and 3.5
When you create your console application make sure your target framework is not set to Client Profile FrameWork 3.5.
The above setting is in Application tab of your project properties
If you want to use GCCollectionMode and Framework 2.0 you will have to install .NET 2.0 Service Pack 1

Is Windows Azure compatible with the .NET 2.0 framework?

I have a service that was developed in the .NET 2.0 framework. It is installed in several sites and works with my application. I would like the service to be able to "report" back to me with certain information about the application. I wanted to see if Windows Azure would be an option for me to be able to store reports in a cloud db and be able to pull them when I need to. One of my main concerns is it compatible with my .NET 2.0 service?
Thank you.
In a word: yes. Windows Azure can run code compiled against 2.0/3.5 and 4.0. You may not have access to all of the Azure SDK (some of the libraries require 3.5), but your service should run with no modifications.