Windows service not working after migrating from 2.2 to 31.

Dinesh Pagadala 1 Reputation point
2020-08-19T05:11:06.313+00:00

Hello,

We are migrating from .net core 2.2 to 3.1
We are facing a system.StackOverflowException exception while running in Kestral.
We are running our web app as a windows service, we are using X509Certificate2 for certificate creation and binded to the application.
code is working fine in 2.2 but in 3.1 the listenOptions.IPEndPoint is not supporting, so i have changed the code in 3.1
Code in 2.2

-----------

.ConfigureKestrel((context, options) =>
{
options.ConfigureEndpointDefaults(listenOptions =>
{
X509Certificate2 certificate = null;

                   // Load certificate from Certificate Store using the configured Thumbprint  
                   using (X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))  
                   {  
                       store.Open(OpenFlags.ReadOnly);  
                       X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);  

                       if (certificates.Count > 0)  
                       {  
                           certificate = certificates[0];  
                       }  

                       store.Close();  
                   }  

                   IPEndPoint ipendpointHTTPS = new IPEndPoint(0, httpsPort);  
                   IPEndPoint ipendpointHTTP = new IPEndPoint(0, httpPort);  

                   if (listenOptions.IPEndPoint.Port == 5001)  
                   {  
                       if (certificate != null)  
                       {  
                           listenOptions.IPEndPoint = ipendpointHTTPS;  
                           listenOptions.UseHttps(certificate);  
                       }  
                   }  
                   else  
                   {  
                       listenOptions.IPEndPoint = ipendpointHTTP;  
                   }  
               });  
           });  

Code in 3.1

-----------

.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel((context, options) =>
{
options.ConfigureEndpointDefaults(listenOptions =>
{
X509Certificate2 certificate = null;

                    // Load certificate from Certificate Store using the configured Thumbprint  
                    using (X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))  
                    {  
                        store.Open(OpenFlags.ReadOnly);  
                        X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);  

                        if (certificates.Count > 0)  
                        {  
                            certificate = certificates[0];  
                        }  

                        store.Close();  
                    }  

                    IPEndPoint ipendpointHTTPS = new IPEndPoint(0, httpsPort);  
                    IPEndPoint ipendpointHTTP = new IPEndPoint(0, httpPort);  

                    if (listenOptions.IPEndPoint.Port == 5001)  
                    {  
                        if (certificate != null)  
                        {  
                            options.Listen(IPAddress.Loopback, httpsPort, listenOptions =>  
                            {  
                                listenOptions.UseHttps(certificate);  
                            });  
                        }  
                    }  
                    else  
                    {  
                        options.Listen(IPAddress.Loopback, httpPort);  
                    }  

                });  
            });  
        })  

18578-overflow.png

Let me know if i'm wrong somewhere?

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,119 questions
{count} votes