When running the webserver, "System.Net.Sockets.SocketException (97): Address family not supported by protocol" message is displayed.

Yiming Chen 0 Reputation points
2024-06-07T09:31:14.17+00:00

Hi experts:

I use asp.net core 8 write a web server app in visual studio 2022, when running on some embedded Linux system, will report the error "System.Net.Sockets.SocketException (97) : Address family not supported by protocol.". The whole stack as follows:

[05:43:59 INF] User profile is available. Using '/home/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest. [05:44:00 ERR] Hosting failed to start System.Net.Sockets.SocketException (97): Address family not supported by protocol    at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)    at System.Net.Sockets.UdpClient.CreateClientSocket()    at System.Net.Sockets.UdpClient..ctor(AddressFamily family)    at Makaretu.Dns.MulticastService..ctor(Func2 filter)    at Makaretu.Dns.ServiceDiscovery..ctor()    at TCAWeb.MdnsBackgroundService.ExecuteAsync(CancellationToken stoppingToken) in C:\Users\xxxWeb\MdnsBackgroundService.cs:line 19    at Microsoft.Extensions.Hosting.BackgroundService.StartAsync(CancellationToken cancellationToken)    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)    at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List1 exceptions, Func3 operation) Unhandled exception. System.Net.Sockets.SocketException (97): Address family not supported by protocol    at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)    at System.Net.Sockets.UdpClient.CreateClientSocket()    at System.Net.Sockets.UdpClient..ctor(AddressFamily family)    at Makaretu.Dns.MulticastService..ctor(Func2 filter)    at Makaretu.Dns.ServiceDiscovery..ctor()    at TCAWeb.MdnsBackgroundService.ExecuteAsync(CancellationToken stoppingToken) in C:\Users\xxxWeb\MdnsBackgroundService.cs:line 19    at Microsoft.Extensions.Hosting.BackgroundService.StartAsync(CancellationToken cancellationToken)    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)    at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List1 exceptions, Func3 operation)    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>g__LogAndRethrow|15_3(<>c__DisplayClass15_0&)    at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)    at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)    at TCAWeb.Program.Main(String[] args) in C:\Users\xxxWeb\Program.cs:line 189

*The embedded linux device supports ipv4, and the webserver app also uses ipv4, and this webserver app has been successfully run on other embedded linux devices. The port used is also not occupied.

I have tried many ways to solve this problem, do you know the reason?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,623 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,382 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,869 questions
{count} votes