Ecng.Net 1.0.491

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Net --version 1.0.491
                    
NuGet\Install-Package Ecng.Net -Version 1.0.491
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ecng.Net" Version="1.0.491" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Net" Version="1.0.491" />
                    
Directory.Packages.props
<PackageReference Include="Ecng.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ecng.Net --version 1.0.491
                    
#r "nuget: Ecng.Net, 1.0.491"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ecng.Net@1.0.491
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ecng.Net&version=1.0.491
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Net&version=1.0.491
                    
Install as a Cake Tool

Ecng.Net

A comprehensive networking library providing essential utilities for working with HTTP, URLs, sockets, multicast, email, and retry policies in .NET applications.

Overview

Ecng.Net is a core networking helper library that simplifies common networking tasks including URL manipulation, HTTP client operations, socket management, multicast operations, email handling, and network path validation. The library is built on .NET Standard 2.0 and supports modern .NET versions including .NET 6.0 and .NET 10.0.

Installation

Add a reference to the Ecng.Net project or NuGet package in your application.

Key Features

  • URL Manipulation: Advanced URL parsing and query string management
  • HTTP Utilities: Headers, authentication schemas, and client extensions
  • Socket Operations: Enhanced socket methods including multicast support
  • Network Helpers: IP address validation, endpoint utilities, and path detection
  • Email Utilities: Email validation and mail message helpers
  • Retry Policies: Configurable retry logic with exponential backoff
  • OAuth Support: OAuth token management interfaces

Core Components

1. URL and Query String Management

The Url and QueryString classes provide powerful URL manipulation capabilities with fluent APIs.

Basic URL Usage
using Ecng.Net;

// Create a URL
var url = new Url("https://api.example.com/data");

// Create URL with base and relative parts
var apiUrl = new Url("https://api.example.com", "/v1/users");

// Clone URL with modifications
var modifiedUrl = url.Clone();
modifiedUrl.Encode = UrlEncodes.Upper; // Use uppercase encoding
Query String Operations
// Working with query strings
var url = new Url("https://api.example.com/search?q=test");

// Access query string
var queryString = url.QueryString;

// Add parameters
queryString.Append("page", 1)
           .Append("limit", 50)
           .Append("sort", "date");

// Get values
int page = queryString.GetValue<int>("page");
string sort = queryString.TryGetValue<string>("sort", "default");

// Check if parameter exists
if (queryString.Contains("q"))
{
    string query = queryString.GetValue<string>("q");
}

// Remove parameters
queryString.Remove("sort");

// Clear all parameters
queryString.Clear();

// Iterate over parameters
foreach (var kvp in queryString)
{
    Console.WriteLine($"{kvp.Key} = {kvp.Value}");
}

// Get raw query string
string rawQuery = queryString.Raw; // Returns "page=1&limit=50"
URL Encoding Options
var url = new Url("https://example.com/api");

// Control encoding behavior
url.Encode = UrlEncodes.None;   // No encoding
url.Encode = UrlEncodes.Lower;  // Lowercase encoding (default)
url.Encode = UrlEncodes.Upper;  // Uppercase encoding

// Keep default page in URL
url.KeepDefaultPage = true;

2. Network Helper Extensions

The NetworkHelper class provides numerous extension methods for common networking tasks.

Endpoint Operations
using System.Net;
using Ecng.Net;

// Check if endpoint is local
var endpoint = new IPEndPoint(IPAddress.Loopback, 8080);
bool isLocal = endpoint.IsLocal(); // true

var dnsEndpoint = new DnsEndPoint("localhost", 8080);
bool isDnsLocal = dnsEndpoint.IsLocal(); // true

// Check if endpoint IP is local
bool isLocalIp = endpoint.IsLocalIpAddress();

// Check if IP is loopback
IPAddress address = IPAddress.Parse("127.0.0.1");
bool isLoopback = address.IsLoopback(); // true
TCP Client Extensions
using System.Net.Sockets;
using Ecng.Net;

var client = new TcpClient();
var endpoint = new DnsEndPoint("api.example.com", 443);

// Async connection with cancellation token
await client.ConnectAsync(endpoint, cancellationToken);
SSL/TLS Stream Creation
using System.IO;
using System.Net.Security;
using System.Security.Authentication;
using Ecng.Net;

Stream networkStream = client.GetStream();

// Convert to SSL stream
var sslStream = networkStream.ToSsl(
    sslProtocol: SslProtocols.Tls12 | SslProtocols.Tls13,
    checkCertificateRevocation: true,
    validateRemoteCertificates: true,
    targetHost: "api.example.com",
    sslCertificate: null, // Optional client certificate path
    sslCertificatePassword: null
);
URL Encoding and Decoding
using Ecng.Net;

// URL encoding
string encoded = "Hello World!".EncodeUrl(); // "Hello+World%21"
string encodedUpper = "test@example".EncodeUrlUpper(); // Uses uppercase hex

// URL decoding
string decoded = "Hello+World%21".DecodeUrl(); // "Hello World!"

// HTML encoding
string htmlEncoded = "<div>Test</div>".EncodeToHtml(); // "&lt;div&gt;Test&lt;/div&gt;"
string htmlDecoded = htmlEncoded.DecodeFromHtml(); // "<div>Test</div>"

// Parse query strings
var parsed = "key1=value1&key2=value2".ParseUrl();

// XML escaping
string xmlSafe = "<tag>value</tag>".XmlEscape(); // "&lt;tag&gt;value&lt;/tag&gt;"

// URL-safe character checking
bool isSafe = '!'.IsUrlSafeChar(); // true
bool isNotSafe = '%'.IsUrlSafeChar(); // false
Encoding Extraction
using System.Text;
using Ecng.Net;

// Extract encoding from Content-Type header
string contentType = "text/html; charset=utf-8";
Encoding encoding = contentType.TryExtractEncoding(); // Returns UTF8 encoding

string noCharset = "application/json";
Encoding fallback = noCharset.TryExtractEncoding(); // Returns null
Query String Helpers
using Ecng.Net;

// Convert dictionary to query string
var parameters = new Dictionary<string, string>
{
    ["api_key"] = "12345",
    ["format"] = "json"
};
string queryString = parameters.ToQueryString(); // "api_key=12345&format=json"

// With URL encoding
var sensitiveParams = new Dictionary<string, string>
{
    ["email"] = "user@example.com",
    ["redirect"] = "https://example.com/callback"
};
string encoded = sensitiveParams.ToQueryString(encodeValue: true);

// Using tuples
var tupleParams = new[]
{
    ("name", "John Doe"),
    ("age", "30")
};
string fromTuples = tupleParams.ToQueryString(); // "name=John Doe&age=30"

3. Multicast Operations

The library provides enhanced multicast support for UDP sockets.

Basic Multicast
using System.Net;
using System.Net.Sockets;
using Ecng.Net;

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var multicastAddress = IPAddress.Parse("239.255.0.1");

// Join multicast group
socket.JoinMulticast(multicastAddress);

// Leave multicast group
socket.LeaveMulticast(multicastAddress);
Source-Specific Multicast
using Ecng.Net;

// Configure source-specific multicast
var multicastConfig = new MulticastSourceAddress
{
    GroupAddress = IPAddress.Parse("239.255.0.1"),
    SourceAddress = IPAddress.Parse("192.168.1.100"),
    Port = 5000,
    IsEnabled = true
};

// Join with source filter
socket.JoinMulticast(multicastConfig);

// Leave source-specific multicast
socket.LeaveMulticast(multicastConfig);

4. HTTP Client Extensions

Convenient extensions for working with HttpClient.

User Agent Configuration
using System.Net.Http;
using Ecng.Net;

var httpClient = new HttpClient();

// Apply Chrome user agent
httpClient.ApplyChromeAgent();
// Sets: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36...
Bearer Token Authentication
using System.Security;
using Ecng.Net;

var httpClient = new HttpClient();
var token = new SecureString();
// ... populate token

// Set bearer authentication
httpClient.SetBearer(token);
// Adds header: Authorization: Bearer {token}
HTTP Headers Constants
using Ecng.Net;

// Use predefined header constants
httpClient.DefaultRequestHeaders.Add(HttpHeaders.UserAgent, "MyApp/1.0");
httpClient.DefaultRequestHeaders.Add(HttpHeaders.AcceptEncoding, "gzip, deflate");
httpClient.DefaultRequestHeaders.Add(HttpHeaders.CacheControl, "no-cache");

// Available constants:
// - Authorization
// - AcceptEncoding
// - AcceptLanguage
// - CacheControl
// - Connection
// - KeepAlive
// - LastModified
// - ProxyAuthenticate
// - ProxyAuthorization
// - ProxyConnection
// - UserAgent
// - Referer
// - WWWAuthenticate

5. Authentication Schemas

Helper methods for formatting authentication headers.

using System.Security;
using Ecng.Net;

// Bearer authentication
var bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
string authHeader = AuthSchemas.Bearer.FormatAuth(bearerToken);
// Returns: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

// Basic authentication
var credentials = "username:password".UTF8().Base64();
string basicAuth = AuthSchemas.Basic.FormatAuth(credentials);
// Returns: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="

// With SecureString
var secureToken = new SecureString();
// ... populate secure token
string secureAuth = AuthSchemas.Bearer.FormatAuth(secureToken);

6. OAuth Support

Interfaces for implementing OAuth authentication flows.

using Ecng.Net;

// Implement OAuth provider
public class MyOAuthProvider : IOAuthProvider
{
    public async Task<IOAuthToken> RequestToken(
        long socialId,
        bool isDemo,
        CancellationToken cancellationToken)
    {
        // Request token from OAuth server
        var token = await GetOAuthTokenAsync(socialId, isDemo);

        return new OAuthToken
        {
            Value = token.AccessToken,
            Expires = DateTime.UtcNow.AddSeconds(token.ExpiresIn)
        };
    }
}

// OAuth token implementation
public class OAuthToken : IOAuthToken
{
    public string Value { get; set; }
    public DateTime? Expires { get; set; }
}

7. Retry Policy with Exponential Backoff

Configure and execute retry logic for network operations.

using System.Net.Sockets;
using Ecng.Net;

// Configure retry policy
var retryPolicy = new RetryPolicyInfo
{
    ReadMaxCount = 5,        // Max retry attempts for reads
    WriteMaxCount = 3,       // Max retry attempts for writes
    InitialDelay = TimeSpan.FromSeconds(1),    // Initial delay
    MaxDelay = TimeSpan.FromSeconds(30)        // Maximum delay cap
};

// Configure which socket errors to retry
retryPolicy.Track.Clear();
retryPolicy.Track.Add(SocketError.TimedOut);
retryPolicy.Track.Add(SocketError.HostNotFound);
retryPolicy.Track.Add(SocketError.ConnectionRefused);

// Execute with retry logic
var result = await retryPolicy.TryRepeat(
    async (ct) =>
    {
        // Your async operation
        return await httpClient.GetStringAsync("https://api.example.com/data", ct);
    },
    maxCount: retryPolicy.ReadMaxCount,
    cancellationToken
);

// Retry delays use exponential backoff with jitter:
// Attempt 1: ~1s + jitter
// Attempt 2: ~2s + jitter
// Attempt 3: ~4s + jitter
// Attempt 4: ~8s + jitter
// Attempt 5: ~16s + jitter (capped at MaxDelay)
Manual Delay Calculation
var policy = new RetryPolicyInfo();

// Calculate delay for specific attempt
TimeSpan delay1 = policy.GetDelay(1); // ~1 second + jitter
TimeSpan delay2 = policy.GetDelay(2); // ~2 seconds + jitter
TimeSpan delay3 = policy.GetDelay(3); // ~4 seconds + jitter

8. Email Utilities

Helpers for working with email messages and SMTP.

Email Validation
using Ecng.Net;

// Validate email format
bool isValid = "user@example.com".IsEmailValid(); // true
bool isInvalid = "invalid.email".IsEmailValid();   // false
Email Message Extensions
using System.Net.Mail;
using Ecng.Net;

var message = new MailMessage
{
    From = new MailAddress("sender@example.com"),
    Subject = "Test Email",
    Body = "Plain text body"
};

message.To.Add("recipient@example.com");

// Add HTML body
message.AddHtml("<html><body><h1>Hello!</h1></body></html>");

// Add plain text alternative
message.AddPlain("Hello in plain text!");

// Attach files
using var fileStream = File.OpenRead("document.pdf");
message.Attach("document.pdf", fileStream);

// Send asynchronously (Note: Method is marked obsolete, use SmtpClient.SendMailAsync directly)
await message.SendAsync(cancellationToken);
Creating Attachments
using System.IO;
using System.Net.Mail;
using System.Net.Mime;
using Ecng.Net;

// Create attachment from stream
using var stream = new MemoryStream(fileBytes);
var attachment = MailHelper.ToAttachment("report.pdf", stream);

// Create attachment with custom encoding
var customAttachment = MailHelper.CreateAttachment(
    stream,
    "report.pdf",
    TransferEncoding.Base64
);

// Attach to message
message.Attachments.Add(attachment);

9. HTTP Status Code Utilities

Extract and work with HTTP status codes from exceptions.

using System.Net;
using System.Net.Http;
using Ecng.Net;

try
{
    await httpClient.GetAsync("https://api.example.com/resource");
}
catch (HttpRequestException ex)
{
    // Try to extract status code
    HttpStatusCode? statusCode = ex.TryGetStatusCode();

    if (statusCode == HttpStatusCode.NotFound)
    {
        Console.WriteLine("Resource not found");
    }
    else if (statusCode == HttpStatusCode.Unauthorized)
    {
        Console.WriteLine("Authentication required");
    }
}

// Create custom HTTP exceptions
var notFoundException = HttpStatusCode.NotFound.CreateHttpRequestException(
    "The requested resource was not found"
);

var unauthorizedException = HttpStatusCode.Unauthorized.CreateHttpRequestException(
    "Invalid API key"
);

// Customize status code phrases for better detection
NetworkHelper.SetStatusCodePhrase(HttpStatusCode.TooManyRequests, "rate limit");

10. Socket Error Handling

Extract socket errors from exceptions.

using System.Net.Sockets;
using Ecng.Net;

try
{
    // Network operation
    await socket.ConnectAsync(endpoint);
}
catch (Exception ex)
{
    // Extract socket error from exception chain
    SocketError? socketError = ex.TryGetSocketError();

    if (socketError == SocketError.TimedOut)
    {
        Console.WriteLine("Connection timed out");
    }
    else if (socketError == SocketError.ConnectionRefused)
    {
        Console.WriteLine("Connection refused by server");
    }
}

11. IP Address and Subnet Operations

Work with IP addresses and subnet calculations.

using System.Net;
using Ecng.Net;

var ipAddress = IPAddress.Parse("192.168.1.100");

// Check if IP is in subnet
bool isInSubnet = ipAddress.IsInSubnet("192.168.1.0/24"); // true
bool notInSubnet = ipAddress.IsInSubnet("10.0.0.0/8");    // false

// Works with IPv6
var ipv6 = IPAddress.Parse("2001:db8::1");
bool isInV6Subnet = ipv6.IsInSubnet("2001:db8::/32"); // true

12. Network Path Detection

Detect various types of network paths and addresses.

using Ecng.Net;

// UNC path detection
bool isUnc1 = @"\\server\share\file.txt".IsUncPath(); // true
bool isUnc2 = "//server/share/file.txt".IsUncPath();  // true

// URL path detection
bool isUrl1 = "https://example.com/path".IsUrlPath(); // true
bool isUrl2 = "http://example.com".IsUrlPath();       // true
bool isUrl3 = "ftp://ftp.example.com".IsUrlPath();    // true

// File URI detection
bool isFileUri = "file:///C:/path/to/file.txt".IsFileUriPath(); // true

// WebDAV path detection
bool isWebDav1 = "dav://server/path".IsWebDavPath();   // true
bool isWebDav2 = "davs://server/path".IsWebDavPath();  // true (secure)

// Host:port address detection
bool isHostPort1 = "127.0.0.1:8080".IsHostPortAddress();     // true
bool isHostPort2 = "localhost:5000".IsHostPortAddress();     // true
bool notHostPort = "C:\\folder".IsHostPortAddress();         // false (Windows path)

// General network path detection (checks all above)
bool isNetwork1 = @"\\server\share".IsNetworkPath();     // true
bool isNetwork2 = "https://example.com".IsNetworkPath(); // true
bool isNetwork3 = "localhost:8080".IsNetworkPath();      // true
bool isLocal = "C:\\local\\file.txt".IsNetworkPath();    // false

13. Image File Detection

Detect image files by extension.

using Ecng.Net;

// Check if file is an image
bool isPng = "photo.png".IsImage();     // true
bool isJpg = "picture.jpg".IsImage();   // true
bool isSvg = "icon.svg".IsImage();      // true
bool isWebP = "image.webp".IsImage();   // true
bool notImage = "document.pdf".IsImage(); // false

// Supported formats: .png, .jpg, .jpeg, .bmp, .gif, .svg,
//                   .webp, .ico, .tiff, .avif, .apng

// Check if file is a vector image
bool isVector = "icon.svg".IsImageVector();  // true
bool notVector = "photo.jpg".IsImageVector(); // false

14. URL Content Detection

Detect URLs in text content.

using Ecng.Net;

// Check if string contains URL patterns
bool hasUrl1 = "Check out https://example.com".CheckContainsUrl(); // true
bool hasUrl2 = "Visit http://site.com".CheckContainsUrl();         // true
bool hasUrl3 = "Link: ftp://files.com".CheckContainsUrl();        // true
bool hasUrl4 = "Click href=page.html".CheckContainsUrl();         // true
bool noUrl = "No URLs here".CheckContainsUrl();                    // false

// Check if Uri is localhost
var localhostUri = new Uri("http://localhost:8080");
bool isLocalhost = localhostUri.IsLocalhost(); // true

var remoteUri = new Uri("https://example.com");
bool notLocalhost = remoteUri.IsLocalhost(); // false

15. Gravatar Support

Generate Gravatar URLs from email addresses.

using Ecng.Net;

string email = "user@example.com";

// Get Gravatar token (MD5 hash of email)
string token = email.GetGravatarToken();
// Returns: "b58996c504c5638798eb6b511e6f49af"

// Get full Gravatar URL
string gravatarUrl = token.GetGravatarUrl(size: 200);
// Returns: "https://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?size=200"

// Complete flow
string avatarUrl = email.GetGravatarToken().GetGravatarUrl(80);

16. URL Safety and Cleaning

Clean and validate URLs for safety.

using Ecng.Net;

// Check URL safety and clean
string unsafeUrl = "Тест URL with спец!@#chars%";
string safeUrl = unsafeUrl.CheckUrl(
    latin: true,   // Convert to Latin characters
    screen: true,  // Apply light screening
    clear: true    // Remove unsafe characters
);

// Individual operations
string cleared = "url%with*unsafe+chars".ClearUrl();
// Removes unsafe URL characters

// Convert to uppercase URL encoding
string upperEncoded = "test@example".UrlEncodeToUpperCase();

Advanced Examples

Complete HTTP Client with Retry Policy

using System.Net.Http;
using System.Net.Sockets;
using Ecng.Net;

public class ResilientHttpClient
{
    private readonly HttpClient _httpClient;
    private readonly RetryPolicyInfo _retryPolicy;

    public ResilientHttpClient()
    {
        _httpClient = new HttpClient();
        _httpClient.ApplyChromeAgent();

        _retryPolicy = new RetryPolicyInfo
        {
            ReadMaxCount = 5,
            InitialDelay = TimeSpan.FromSeconds(1),
            MaxDelay = TimeSpan.FromSeconds(30)
        };

        _retryPolicy.Track.Add(SocketError.TimedOut);
        _retryPolicy.Track.Add(SocketError.ConnectionReset);
    }

    public async Task<string> GetWithRetryAsync(
        string url,
        CancellationToken ct = default)
    {
        return await _retryPolicy.TryRepeat(
            async (token) =>
            {
                var response = await _httpClient.GetAsync(url, token);
                response.EnsureSuccessStatusCode();
                return await response.Content.ReadAsStringAsync();
            },
            maxCount: _retryPolicy.ReadMaxCount,
            cancellationToken: ct
        );
    }
}

// Usage
var client = new ResilientHttpClient();
var data = await client.GetWithRetryAsync("https://api.example.com/data");

Building API URLs with Query Parameters

using Ecng.Net;

public class ApiClient
{
    private readonly Url _baseUrl;

    public ApiClient(string apiBaseUrl)
    {
        _baseUrl = new Url(apiBaseUrl);
    }

    public string BuildSearchUrl(string query, int page, int pageSize, string sortBy)
    {
        var url = _baseUrl.Clone();
        url.QueryString
            .Append("q", query)
            .Append("page", page)
            .Append("pageSize", pageSize)
            .Append("sort", sortBy);

        return url.ToString();
    }

    public string BuildFilteredUrl(Dictionary<string, object> filters)
    {
        var url = _baseUrl.Clone();

        foreach (var filter in filters)
        {
            url.QueryString.Append(filter.Key, filter.Value);
        }

        return url.ToString();
    }
}

// Usage
var client = new ApiClient("https://api.example.com/search");
var searchUrl = client.BuildSearchUrl("stocks", 1, 20, "date");
// Returns: https://api.example.com/search?page=1&pageSize=20&q=stocks&sort=date

Multicast UDP Receiver

using System.Net;
using System.Net.Sockets;
using System.Text;
using Ecng.Net;

public class MulticastReceiver : IDisposable
{
    private readonly Socket _socket;
    private readonly MulticastSourceAddress _config;

    public MulticastReceiver(string groupAddress, string sourceAddress, int port)
    {
        _config = new MulticastSourceAddress
        {
            GroupAddress = IPAddress.Parse(groupAddress),
            SourceAddress = IPAddress.Parse(sourceAddress),
            Port = port,
            IsEnabled = true
        };

        _socket = new Socket(
            AddressFamily.InterNetwork,
            SocketType.Dgram,
            ProtocolType.Udp
        );

        _socket.SetSocketOption(
            SocketOptionLevel.Socket,
            SocketOptionName.ReuseAddress,
            true
        );

        _socket.Bind(new IPEndPoint(IPAddress.Any, _config.Port));
        _socket.JoinMulticast(_config);
    }

    public async Task<string> ReceiveAsync(CancellationToken ct = default)
    {
        var buffer = new byte[NetworkHelper.MtuSize];
        var received = await _socket.ReceiveAsync(buffer, SocketFlags.None, ct);
        return Encoding.UTF8.GetString(buffer, 0, received);
    }

    public void Dispose()
    {
        if (_config.IsEnabled)
        {
            _socket.LeaveMulticast(_config);
        }
        _socket.Dispose();
    }
}

// Usage
using var receiver = new MulticastReceiver("239.255.0.1", "192.168.1.100", 5000);
var message = await receiver.ReceiveAsync(cancellationToken);

Constants

Maximum Transmission Unit (MTU)

using Ecng.Net;

// Standard MTU size for network operations
int mtuSize = NetworkHelper.MtuSize; // 1600 bytes

Best Practices

  1. URL Encoding: Always encode user input when building URLs to prevent injection attacks.

  2. Retry Policies: Configure retry policies based on your network reliability requirements. Use exponential backoff to avoid overwhelming servers.

  3. Cancellation Tokens: Always pass cancellation tokens to async operations for proper cleanup.

  4. Resource Disposal: Dispose of sockets, HTTP clients, and mail messages properly using using statements.

  5. Security: Use SecureString for sensitive tokens and credentials when possible.

  6. Error Handling: Always catch and handle network exceptions appropriately. Use TryGetSocketError and TryGetStatusCode for detailed error information.

  7. SSL/TLS: Always validate certificates in production environments. Only disable validation for testing purposes.

  8. Multicast: Remember to leave multicast groups when done to free up system resources.

Dependencies

  • .NET Standard 2.0+
  • Ecng.ComponentModel
  • Newtonsoft.Json

Thread Safety

Most classes in this library are not thread-safe by default. When using from multiple threads:

  • Use proper synchronization for shared instances
  • Consider using thread-safe collections like SynchronizedSet where available
  • Create separate instances per thread when possible

Performance Considerations

  • Query String: Query strings are compiled and cached. Modifications trigger recompilation.
  • Retry Policy: Uses jitter to prevent thundering herd problems.
  • URL Encoding: Encoding operations allocate new strings. Cache results when possible.
  • Socket Operations: Reuse sockets when possible to avoid connection overhead.

Platform Support

  • .NET Standard 2.0
  • .NET 6.0
  • .NET 10.0
  • Cross-platform (Windows, Linux, macOS)

License

Part of the StockSharp/Ecng project. Please refer to the main project license for details.

  • Ecng.Common: Core utilities and extensions
  • Ecng.Collections: Thread-safe collections
  • Ecng.ComponentModel: Component model utilities

Contributing

This library is part of the Ecng ecosystem. For contributions, please refer to the main project guidelines.

Support

For issues, questions, or contributions related to Ecng.Net, please visit the main project repository.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on Ecng.Net:

Package Downloads
StockSharp.Algo

Trading algorithms. More info on web site https://stocksharp.com/store/

Ecng.Net.SocketIO

Ecng system framework

StockSharp.Fix.Core

Fix core. More info on web site https://stocksharp.com/store/

StockSharp.FinViz

Trading and algorithmic trading platform (stock markets, forex, bitcoins and options). .NET API for InteractiveBrokers, GainCapital, OANDA, FIX/FAST, Binance etc. More info on web site https://stocksharp.com/store/api/

StockSharp.AlorHistory

AlorHistory

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Ecng.Net:

Repository Stars
StockSharp/StockSharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
Version Downloads Last Updated
1.0.493 181 2/4/2026
1.0.492 110 2/4/2026
1.0.491 649 2/1/2026
1.0.490 451 1/26/2026
1.0.489 199 1/26/2026
1.0.488 216 1/22/2026
1.0.487 210 1/22/2026
1.0.486 223 1/21/2026
1.0.485 303 1/19/2026
1.0.484 185 1/19/2026
1.0.483 185 1/18/2026
1.0.482 192 1/18/2026
1.0.481 197 1/16/2026
1.0.480 254 1/14/2026
1.0.479 190 1/13/2026
1.0.478 189 1/13/2026
1.0.477 196 1/12/2026
1.0.476 280 1/9/2026
1.0.475 230 1/9/2026
1.0.474 197 1/8/2026
1.0.473 192 1/8/2026
1.0.472 194 1/7/2026
1.0.471 228 1/6/2026
1.0.470 190 1/6/2026
1.0.469 200 1/5/2026
1.0.468 235 1/4/2026
1.0.467 180 1/1/2026
1.0.466 175 12/31/2025
1.0.465 183 12/30/2025
1.0.464 167 12/30/2025
1.0.463 180 12/29/2025
1.0.462 180 12/29/2025
1.0.461 203 12/26/2025
1.0.460 177 12/26/2025
1.0.459 180 12/26/2025
1.0.458 190 12/26/2025
1.0.457 266 12/25/2025
1.0.456 268 12/25/2025
1.0.455 264 12/24/2025
1.0.454 272 12/23/2025
1.0.453 258 12/22/2025
1.0.452 304 12/21/2025
1.0.451 327 12/19/2025
1.0.450 314 12/19/2025
1.0.449 377 12/18/2025
1.0.448 395 12/17/2025
1.0.447 408 12/15/2025
1.0.446 338 12/15/2025
1.0.445 314 12/14/2025
1.0.444 239 12/14/2025
1.0.443 252 12/13/2025
1.0.442 254 12/13/2025
1.0.441 245 12/12/2025
1.0.440 191 12/12/2025
1.0.439 209 12/12/2025
1.0.438 187 12/12/2025
1.0.437 200 12/12/2025
1.0.436 217 12/12/2025
1.0.435 205 12/12/2025
1.0.434 890 12/2/2025
1.0.433 775 12/2/2025
1.0.432 778 12/2/2025
1.0.431 380 11/30/2025
1.0.430 241 11/29/2025
1.0.429 245 11/28/2025
1.0.428 238 11/28/2025
1.0.427 297 11/27/2025
1.0.426 383 11/24/2025
1.0.425 291 11/24/2025
1.0.424 298 11/23/2025
1.0.423 262 11/23/2025
1.0.422 348 11/22/2025
1.0.421 1,346 11/20/2025
1.0.420 544 11/18/2025
1.0.419 497 11/18/2025
1.0.418 494 11/13/2025
1.0.417 389 11/10/2025
1.0.416 1,281 11/1/2025
1.0.415 331 10/31/2025
1.0.414 325 10/28/2025
1.0.413 478 10/27/2025
1.0.412 318 10/27/2025
1.0.411 242 10/25/2025
1.0.410 285 10/24/2025
1.0.409 477 10/20/2025
1.0.408 521 10/12/2025
1.0.407 265 10/11/2025
1.0.406 561 10/7/2025
1.0.405 396 10/6/2025
1.0.404 576 10/3/2025
1.0.403 416 10/1/2025
1.0.402 316 10/1/2025
1.0.401 344 9/30/2025
1.0.400 342 9/28/2025
1.0.399 383 9/25/2025
1.0.398 4,603 9/5/2025
1.0.397 371 9/2/2025
1.0.396 4,602 8/30/2025
1.0.395 509 8/30/2025
1.0.394 523 8/20/2025
1.0.393 302 8/20/2025
1.0.392 328 8/19/2025
1.0.391 359 8/15/2025
1.0.390 1,061 8/10/2025
1.0.389 2,669 7/16/2025
1.0.388 911 7/14/2025
1.0.387 362 7/13/2025
1.0.386 308 7/13/2025
1.0.385 291 7/12/2025
1.0.384 1,332 7/8/2025
1.0.383 732 7/4/2025
1.0.382 347 7/2/2025
1.0.381 852 6/24/2025
1.0.380 3,850 6/16/2025
1.0.379 501 6/9/2025
1.0.378 391 6/8/2025
1.0.377 1,126 5/21/2025
1.0.376 318 5/21/2025
1.0.375 338 5/17/2025
1.0.374 1,168 5/12/2025
1.0.373 408 5/12/2025
1.0.372 394 5/12/2025
1.0.371 318 5/11/2025
1.0.370 304 5/11/2025
1.0.369 249 5/10/2025
1.0.368 261 5/10/2025
1.0.367 359 5/6/2025
1.0.366 277 5/3/2025
1.0.365 468 4/17/2025
1.0.364 414 4/15/2025
1.0.363 320 4/12/2025
1.0.362 374 4/9/2025
1.0.361 1,752 4/6/2025
1.0.360 300 4/5/2025
1.0.359 2,004 3/22/2025
1.0.358 325 3/20/2025
1.0.357 322 3/20/2025
1.0.356 322 3/19/2025
1.0.355 1,963 2/26/2025
1.0.354 293 2/26/2025
1.0.353 2,001 2/8/2025
1.0.352 295 2/8/2025
1.0.351 293 2/8/2025
1.0.350 285 2/6/2025
1.0.349 303 2/6/2025
1.0.348 289 2/6/2025
1.0.347 316 2/6/2025
1.0.346 267 2/6/2025
1.0.345 5,651 2/5/2025
1.0.344 292 2/5/2025
1.0.343 298 2/5/2025
1.0.342 663 2/3/2025
1.0.341 292 2/2/2025
1.0.340 307 2/1/2025
1.0.339 311 1/31/2025
1.0.338 303 1/30/2025
1.0.337 310 1/26/2025
1.0.336 307 1/21/2025
1.0.335 301 1/20/2025
1.0.334 271 1/20/2025
1.0.333 302 1/19/2025
1.0.332 252 1/19/2025
1.0.331 554 1/15/2025
1.0.330 451 1/15/2025
1.0.329 499 1/14/2025
1.0.328 299 1/12/2025
1.0.327 265 1/12/2025
1.0.326 281 1/12/2025
1.0.325 265 1/12/2025
1.0.324 285 1/10/2025
1.0.323 2,149 12/30/2024
1.0.322 332 12/27/2024
1.0.321 341 12/19/2024
1.0.320 785 11/20/2024
1.0.319 320 11/19/2024
1.0.318 302 11/19/2024
1.0.317 2,548 11/18/2024
1.0.316 1,379 11/7/2024
1.0.315 361 10/31/2024
1.0.314 633 10/19/2024
1.0.313 430 10/19/2024
1.0.312 2,310 10/13/2024
1.0.311 311 10/12/2024
1.0.310 1,013 10/9/2024
1.0.309 321 10/9/2024
1.0.308 996 10/5/2024
1.0.307 2,947 9/18/2024
1.0.306 326 9/18/2024
1.0.305 1,582 9/18/2024
1.0.304 362 9/17/2024
1.0.303 2,060 9/3/2024
1.0.302 360 9/1/2024
1.0.301 2,637 8/8/2024
1.0.300 3,733 7/23/2024
1.0.299 2,049 7/4/2024
1.0.298 2,631 6/12/2024
1.0.297 573 6/12/2024
1.0.296 363 6/12/2024
1.0.295 1,526 5/28/2024
1.0.294 2,380 5/4/2024
1.0.293 1,506 4/23/2024
1.0.292 1,797 4/21/2024
1.0.291 544 4/14/2024
1.0.290 2,696 3/28/2024
1.0.289 424 3/17/2024
1.0.288 1,738 3/9/2024
1.0.287 1,156 2/23/2024
1.0.286 384 2/23/2024
1.0.285 1,843 2/18/2024
1.0.284 330 2/18/2024
1.0.283 395 2/16/2024
1.0.282 1,308 2/13/2024
1.0.281 1,162 2/8/2024
1.0.280 1,435 2/5/2024
1.0.279 345 2/4/2024
1.0.278 1,451 1/23/2024
1.0.277 341 1/23/2024
1.0.276 2,061 1/12/2024
1.0.275 2,587 1/2/2024
1.0.274 540 12/29/2023
1.0.273 778 12/17/2023
1.0.272 1,701 12/15/2023
1.0.271 390 12/15/2023
1.0.270 356 12/15/2023
1.0.269 817 12/13/2023
1.0.268 384 12/13/2023
1.0.267 408 12/10/2023
1.0.266 5,214 11/18/2023
1.0.265 386 11/18/2023
1.0.264 418 11/18/2023
1.0.263 375 11/17/2023
1.0.262 389 11/12/2023
1.0.261 338 11/12/2023
1.0.260 358 11/10/2023
1.0.259 360 11/10/2023
1.0.258 572 11/9/2023
1.0.257 362 11/9/2023
1.0.256 360 11/9/2023
1.0.255 734 11/3/2023
1.0.254 348 11/1/2023
1.0.253 337 11/1/2023
1.0.252 18,101 9/8/2023
1.0.251 597 9/8/2023
1.0.250 571 9/3/2023
1.0.249 490 8/27/2023
1.0.248 416 8/24/2023
1.0.247 418 8/21/2023
1.0.246 855 8/15/2023
1.0.245 464 8/14/2023
1.0.244 401 8/14/2023
1.0.243 1,022 8/10/2023
1.0.242 8,763 7/29/2023
1.0.241 22,931 7/1/2023
1.0.240 540 6/29/2023
1.0.239 11,349 5/27/2023
1.0.238 804 5/21/2023
1.0.237 941 5/19/2023
1.0.236 18,729 5/8/2023
1.0.235 564 5/7/2023
1.0.234 2,767 5/1/2023
1.0.233 2,102 4/22/2023
1.0.232 619 4/21/2023
1.0.231 600 4/21/2023
1.0.230 19,300 4/13/2023
1.0.229 19,570 4/3/2023
1.0.228 2,464 3/27/2023
1.0.227 1,905 3/21/2023
1.0.226 1,461 3/17/2023
1.0.225 1,165 3/13/2023
1.0.224 11,853 3/6/2023
1.0.223 1,837 2/26/2023
1.0.222 13,006 2/21/2023
1.0.221 831 2/20/2023
1.0.220 1,805 2/16/2023
1.0.219 840 2/15/2023
1.0.218 765 2/14/2023
1.0.217 756 2/14/2023
1.0.216 24,105 2/9/2023
1.0.215 14,133 2/7/2023
1.0.214 902 2/4/2023
1.0.213 846 2/4/2023
1.0.212 882 2/3/2023
1.0.211 1,017 2/3/2023
1.0.210 14,491 2/2/2023
1.0.209 13,537 1/30/2023
1.0.208 2,160 1/30/2023
1.0.207 3,024 1/25/2023
1.0.206 926 1/23/2023
1.0.205 872 1/23/2023
1.0.204 1,473 1/18/2023
1.0.203 901 1/15/2023
1.0.202 1,554 1/6/2023
1.0.201 16,682 1/1/2023
1.0.200 943 12/31/2022
1.0.199 13,659 12/30/2022
1.0.198 963 12/29/2022
1.0.197 2,011 12/23/2022
1.0.196 14,564 12/12/2022
1.0.195 15,886 12/8/2022
1.0.194 2,783 12/4/2022
1.0.193 1,000 12/4/2022
1.0.192 1,033 12/2/2022
1.0.191 1,035 11/30/2022
1.0.190 990 11/29/2022
1.0.189 980 11/28/2022
1.0.188 1,022 11/26/2022
1.0.187 982 11/26/2022
1.0.186 830 11/25/2022
1.0.185 832 11/25/2022
1.0.184 2,905 11/18/2022
1.0.183 17,688 11/11/2022
1.0.182 832 11/11/2022
1.0.181 816 11/10/2022
1.0.180 910 11/5/2022
1.0.179 2,309 11/4/2022
1.0.178 884 11/2/2022
1.0.177 831 11/2/2022
1.0.176 19,048 11/1/2022
1.0.175 21,370 10/16/2022
1.0.174 3,331 9/25/2022
1.0.173 3,230 9/10/2022
1.0.172 42,841 9/8/2022
1.0.171 1,059 9/8/2022
1.0.170 1,109 9/8/2022
1.0.169 1,001 9/4/2022
1.0.168 1,009 9/4/2022
1.0.167 84,039 8/24/2022
1.0.166 5,260 8/8/2022
1.0.165 1,041 8/8/2022
1.0.164 4,131 7/26/2022
1.0.163 993 7/26/2022
1.0.162 43,607 7/21/2022
1.0.161 1,047 7/19/2022
1.0.160 42,793 7/18/2022
1.0.159 4,313 7/13/2022
1.0.158 1,085 7/8/2022
1.0.157 2,023 6/30/2022
1.0.156 1,075 6/20/2022
1.0.155 2,012 6/18/2022
1.0.154 1,084 6/6/2022
1.0.153 85,200 4/30/2022
1.0.152 1,084 4/20/2022
1.0.151 1,097 4/10/2022
1.0.150 1,068 4/7/2022
1.0.149 1,038 4/7/2022
1.0.148 1,096 4/2/2022
1.0.147 7,721 3/29/2022
1.0.146 1,019 3/27/2022
1.0.145 1,060 3/27/2022
1.0.144 48,544 3/24/2022
1.0.143 51,996 2/20/2022
1.0.142 1,025 2/20/2022
1.0.141 1,067 2/20/2022
1.0.140 1,029 2/20/2022
1.0.139 1,095 2/20/2022
1.0.138 1,024 2/20/2022
1.0.137 1,027 2/20/2022
1.0.136 1,046 2/20/2022
1.0.135 1,025 2/20/2022
1.0.134 1,071 2/19/2022
1.0.133 86,181 2/10/2022
1.0.132 27,637 1/27/2022
1.0.131 1,076 1/27/2022
1.0.130 44,118 1/24/2022
1.0.129 1,063 1/24/2022
1.0.128 1,080 1/23/2022
1.0.127 148,541 12/29/2021
1.0.126 783 12/27/2021
1.0.125 766 12/27/2021
1.0.124 792 12/27/2021
1.0.123 26,107 12/20/2021
1.0.122 811 12/17/2021
1.0.121 770 12/16/2021
1.0.120 767 12/15/2021
1.0.119 759 12/14/2021
1.0.118 756 12/14/2021
1.0.117 747 12/13/2021
1.0.116 877 12/12/2021
1.0.115 26,204 12/10/2021
1.0.114 807 12/7/2021
1.0.113 807 12/7/2021
1.0.112 26,323 12/6/2021
1.0.111 810 12/6/2021
1.0.110 815 12/5/2021
1.0.109 1,509 12/3/2021
1.0.108 1,265 12/3/2021
1.0.107 846 12/2/2021
1.0.106 27,799 11/29/2021
1.0.105 5,508 11/23/2021
1.0.104 799 11/23/2021
1.0.103 25,951 11/22/2021
1.0.102 900 11/17/2021
1.0.101 829 11/14/2021
1.0.100 26,876 11/13/2021
1.0.99 843 11/11/2021
1.0.98 845 11/11/2021
1.0.97 811 11/10/2021
1.0.96 806 11/9/2021
1.0.95 29,448 11/6/2021
1.0.94 909 11/6/2021
1.0.93 28,632 11/5/2021
1.0.92 896 11/5/2021
1.0.91 862 11/4/2021
1.0.90 846 11/4/2021
1.0.89 899 11/3/2021
1.0.88 957 10/30/2021
1.0.87 29,614 10/21/2021
1.0.86 921 10/17/2021
1.0.85 936 10/17/2021
1.0.84 55,438 10/14/2021
1.0.83 1,940 10/13/2021
1.0.82 4,145 10/13/2021
1.0.81 844 10/12/2021
1.0.80 29,309 10/11/2021
1.0.79 818 10/9/2021
1.0.78 32,595 10/7/2021
1.0.77 31,368 10/7/2021
1.0.76 859 10/7/2021
1.0.75 873 10/6/2021
1.0.74 913 9/28/2021
1.0.73 30,531 9/23/2021
1.0.72 999 9/11/2021
1.0.71 894 9/10/2021
1.0.70 923 9/9/2021
1.0.69 848 9/8/2021
1.0.68 901 9/8/2021
1.0.67 28,982 9/6/2021
1.0.66 1,015 8/31/2021
1.0.65 834 8/30/2021
1.0.64 29,971 7/31/2021
1.0.63 54,903 7/30/2021
1.0.62 978 7/26/2021
1.0.61 82,111 7/5/2021
1.0.60 911 7/1/2021
1.0.59 57,696 6/4/2021
1.0.58 83,229 4/26/2021
1.0.57 29,071 4/19/2021
1.0.56 108,798 4/8/2021
1.0.55 28,340 4/7/2021
1.0.54 877 4/7/2021
1.0.53 28,289 4/3/2021
1.0.52 163,257 3/22/2021
1.0.51 102,104 3/4/2021
1.0.50 28,295 2/26/2021
1.0.49 151,340 2/2/2021
1.0.48 52,001 1/26/2021
1.0.47 51,208 1/24/2021
1.0.46 910 1/24/2021
1.0.45 1,050 1/23/2021
1.0.44 52,348 1/20/2021
1.0.43 966 1/20/2021
1.0.42 26,675 1/18/2021
1.0.41 975 1/18/2021
1.0.40 25,658 1/16/2021
1.0.39 104,825 12/17/2020
1.0.38 1,045 12/16/2020
1.0.37 53,240 12/14/2020
1.0.36 30,311 12/9/2020
1.0.35 986 12/9/2020
1.0.34 1,025 12/7/2020
1.0.33 1,166 12/6/2020
1.0.32 1,093 12/2/2020
1.0.31 1,021 12/2/2020
1.0.30 26,703 12/1/2020
1.0.29 146,241 11/12/2020
1.0.29-atestpub 669 11/11/2020
1.0.28 27,294 10/11/2020
1.0.27 100,642 9/9/2020
1.0.26 25,949 9/3/2020
1.0.25 26,444 8/20/2020
1.0.24 76,237 8/9/2020
1.0.23 25,947 7/28/2020
1.0.22 25,991 7/19/2020
1.0.21 49,737 7/6/2020
1.0.20 76,735 6/6/2020
1.0.19 26,824 6/4/2020
1.0.18 51,502 5/29/2020
1.0.17 51,468 5/21/2020
1.0.16 1,177 5/17/2020
1.0.15 52,143 5/12/2020
1.0.14 103,444 5/4/2020
1.0.13 1,248 4/24/2020
1.0.12 4,377 4/22/2020
1.0.11 1,058 4/22/2020
1.0.10 1,097 4/21/2020
1.0.9 28,517 4/18/2020
1.0.8 26,493 4/16/2020
1.0.7 1,045 4/16/2020
1.0.6 22,330 4/15/2020
1.0.5 24,038 4/11/2020
1.0.4 23,697 4/3/2020
1.0.3 1,075 4/1/2020
1.0.2 10,455 3/27/2020
1.0.1 9,402 3/22/2020
1.0.0 3,013 3/22/2020