From 286bf95390b21df27fd2e9545fbf6a57d3eee477 Mon Sep 17 00:00:00 2001 From: Laurent Brusa Date: Sun, 12 Oct 2025 16:38:36 +0200 Subject: [PATCH] updated for net9.0 --- CANAPE.Cli.Lib/.DS_Store | Bin 0 -> 6148 bytes CANAPE.Cli.Lib/CANAPE.Cli.Lib.csproj | 2 +- CANAPE.Cli/CANAPE.Cli.csproj | 2 +- CANAPE.Net.Protocols/.DS_Store | Bin 0 -> 6148 bytes .../CANAPE.Net.Protocols.csproj | 2 +- CANAPE.Net.Templates/.DS_Store | Bin 0 -> 6148 bytes .../CANAPE.Net.Templates.csproj | 2 +- CANAPE.Net/.DS_Store | Bin 0 -> 8196 bytes CANAPE.Net/CANAPE.Net.csproj | 2 +- CANAPE.Net/Listeners/TcpNetworkListener.cs | 5 ++ CANAPE.Security/CANAPE.Security.csproj | 2 +- CANAPE/.DS_Store | Bin 0 -> 6148 bytes CANAPE/CANAPE.csproj | 2 +- NET9_MIGRATION.md | 69 ++++++++++++++++++ README.md | 13 ++-- 15 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 CANAPE.Cli.Lib/.DS_Store create mode 100644 CANAPE.Net.Protocols/.DS_Store create mode 100644 CANAPE.Net.Templates/.DS_Store create mode 100644 CANAPE.Net/.DS_Store create mode 100644 CANAPE/.DS_Store create mode 100644 NET9_MIGRATION.md diff --git a/CANAPE.Cli.Lib/.DS_Store b/CANAPE.Cli.Lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..917c0759ac8d8a17e016e9bf382cc6cda7569da6 GIT binary patch literal 6148 zcmeHKOHRWu5PdFP1lUxpSo#XNL8#I_QZE4g2#^vb;v=#2h68Z~j>1iN<1sBEiNp#) zH6x9mGk)VZFKxyK;O0-89GC&f=z^1DHUlQ(;ys(Bhzz - netstandard2.0 + net9.0 true James Forshaw Command Line Interface library for the CANAPE.Core network library. diff --git a/CANAPE.Cli/CANAPE.Cli.csproj b/CANAPE.Cli/CANAPE.Cli.csproj index e86d4f4..778eb7b 100644 --- a/CANAPE.Cli/CANAPE.Cli.csproj +++ b/CANAPE.Cli/CANAPE.Cli.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0; netcoreapp2.0; net471 + net9.0 true James Forshaw Command Line Interface CANAPE.Core network library. diff --git a/CANAPE.Net.Protocols/.DS_Store b/CANAPE.Net.Protocols/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a35ccd3eef0c0cc01fb37210fd19e3052ef70705 GIT binary patch literal 6148 zcmeHKJx{|h5PgQKs>;%l(E}4(2lh~775)XL7cDWc9jcgrI z1yq4UQ^0QkV}7+WRQU1zPRmv0$qvqmJ?!PI$~>Pe%ZZBt)3?u$%l5q4ukxz z+M_RraVvA4u(Am^6ysLsxOM3;nMZ9^0aYMY;MhM7 - netstandard2.0 + net9.0 true James Forshaw Network protocol parsing library for the CANAPE.Core network library. diff --git a/CANAPE.Net.Templates/.DS_Store b/CANAPE.Net.Templates/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fcbf4a776b0efd97c3baf8da6cf7f9445936bd14 GIT binary patch literal 6148 zcmeHKOHRW;41H6&XkpVO%eg{t5URi$sTY8zh>sd2DzMLnYj78i!47V~5qKV3RjMQs zD+HA-dEUfhPn?%g90Lf8=k*+z0hmw)M^g?xBI}|Z8JR^EL)xRl7WcTp~==UnCJYQ|96<1}S;^p)0Y{+x{L(lrIb>|Sd9gcCy zb5)_{$=WhYJ7Fz9ynhY(4dmFnXIb@T+3UNPCq5)k7iYj3a0dPh1FYF1lM_WBodIXS z8Q3u(--k#Q%nTdF^y%P`S^(mh<|Ld;FCj6}Ff(ivxk3pVO4QI`Ek@9A+N1ephK-_z zBUtkh?9RbDl#uSu{bO=R$P|5a2AqL?29ES{CiVY(xc}b|@+)V+88|2g!Z=^%3qF$7 x*3QF8t&P+xs)+bCin|a_QYogdl;Trr6569oh?!xdNDIY(1QHECI0L`Rz&CLkRAc}E literal 0 HcmV?d00001 diff --git a/CANAPE.Net.Templates/CANAPE.Net.Templates.csproj b/CANAPE.Net.Templates/CANAPE.Net.Templates.csproj index efb73c6..daa6d4e 100644 --- a/CANAPE.Net.Templates/CANAPE.Net.Templates.csproj +++ b/CANAPE.Net.Templates/CANAPE.Net.Templates.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net9.0 true James Forshaw Network service template library for the CANAPE.Core network library. diff --git a/CANAPE.Net/.DS_Store b/CANAPE.Net/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e029fba5269521449daf56b5e7ce6a5958443a55 GIT binary patch literal 8196 zcmeHLyG|T26g^IWC66NMD5s#Hgg+Qyph^*Gvn3LbMFcUsvkC->ZiJMt$Pc7UpDLfg zC*%+K1kSzoO6wUrN{UD!xt8p+vd^{8p7D%z4Z!Vu9B%<@09IKAU%g$9!lNz-FnhdE#lm;>g3IbaU_4G!?kma>{T_x-4~=72fyUpgS)hk{kG z4A^?qPX`-K0f_Ud(baloRN{1^wT5ArN1APZ1cOPIEHO_Imn7>bEp8V~g&zLk-bzC>c9Ff=V0+H$yMEVaWHff>$tdfvVm+nkS-~5+ca!kW?H+c=Gg_iKGD;#&q{DsXGI&NE z=eSf~rU^B;y-2e%niBJ6lqHyvKB&Iuc+1_@aG%L8yV5ry++xl5+UE@_O!6`sGu-4J zOL7xB2Nx74H^Og!bjEuG(E2*l(iu5@BIIQ3uUAv%~Y4_bMzfesyp3&0bB$Y&* zNCzJo%Q8m#)atH^n^8QP(XbGo*+&bEczxYJqQQze@Yo!9>IJV!{=b*M|9@ - netstandard2.0 + net9.0 true James Forshaw Core networking library for the CANAPE.Core network library. diff --git a/CANAPE.Net/Listeners/TcpNetworkListener.cs b/CANAPE.Net/Listeners/TcpNetworkListener.cs index 49e7d81..01f8fde 100644 --- a/CANAPE.Net/Listeners/TcpNetworkListener.cs +++ b/CANAPE.Net/Listeners/TcpNetworkListener.cs @@ -162,6 +162,11 @@ private async Task AcceptCallback(TcpListener listener) // If client socket closed then exit loop. break; } + catch (InvalidOperationException) + { + // In .NET 9.0+, TcpListener throws InvalidOperationException when stopped + break; + } catch (Exception ex) { _logger.LogException(ex); diff --git a/CANAPE.Security/CANAPE.Security.csproj b/CANAPE.Security/CANAPE.Security.csproj index 1b14414..e09fc21 100644 --- a/CANAPE.Security/CANAPE.Security.csproj +++ b/CANAPE.Security/CANAPE.Security.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net9.0 true James Forshaw Network security and certificate generator library for the CANAPE.Core network library. diff --git a/CANAPE/.DS_Store b/CANAPE/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dbee2063120e9410429d4e9434d665847265a9b3 GIT binary patch literal 6148 zcmeHLK}rKL6#c0kC{>|Lm*WxYUYM4#OA(4Y7qy+DLWe1}?q}oD19%I;3+M$rgWkmV zlTap|WS|?7@;@YRCV4-3ebY&r5|J7{WqqO^5p_@)+g((i;C?Q(XxWw%pweRuD5G0i z(wgQqwls(X;=q4%fZyFCO7YgNQL69niXInt{qd~GmqzrO}#k{@ug!f@tqO?dt;UBRyc z`^p@+_BnU+9pVKvdB+T>^Ku=XkcNopTB}=ZeG8-0FSj?KsgfU1QeimrNBkgm4)b)W zbGUP+B!~mzz`i@c>qCsfm{=?g>ZJpfJ^}#SXx4%29$x@si;2b3AbJqWqykNJ(IVJJuJx74!cJI?xyM1u(H#8bk|1eh6qA Kq!I`I)PY~o=h)K# literal 0 HcmV?d00001 diff --git a/CANAPE/CANAPE.csproj b/CANAPE/CANAPE.csproj index 8bbbcc4..a6f09f2 100644 --- a/CANAPE/CANAPE.csproj +++ b/CANAPE/CANAPE.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net9.0 true James Forshaw Base library for the CANAPE.Core network library. diff --git a/NET9_MIGRATION.md b/NET9_MIGRATION.md new file mode 100644 index 0000000..d8d5f7a --- /dev/null +++ b/NET9_MIGRATION.md @@ -0,0 +1,69 @@ +# .NET 9.0 Migration Notes + +This document describes the changes made to migrate CANAPE.Core from .NET Standard 2.0/.NET Core 2.0/3.0 to .NET 9.0. + +## Project Files Updated + +All project files were updated to target .NET 9.0: + +1. **CANAPE.csproj** - Changed from `netstandard2.0` to `net9.0` +2. **CANAPE.Net.csproj** - Changed from `netstandard2.0` to `net9.0` +3. **CANAPE.Security.csproj** - Changed from `netstandard2.0` to `net9.0` +4. **CANAPE.Net.Protocols.csproj** - Changed from `netstandard2.0` to `net9.0` +5. **CANAPE.Net.Templates.csproj** - Changed from `netstandard2.0` to `net9.0` +6. **CANAPE.Cli.csproj** - Changed from `netcoreapp3.0; netcoreapp2.0; net471` to `net9.0` +7. **CANAPE.Cli.Lib.csproj** - Changed from `netstandard2.0` to `net9.0` + +## Code Changes Required + +### TcpNetworkListener.cs + +**Issue**: In .NET 9.0, `TcpListener.Stop()` behavior changed. When stopped, subsequent calls to `AcceptTcpClientAsync()` now throw `InvalidOperationException` instead of `ObjectDisposedException`. + +**Fix**: Added exception handling for `InvalidOperationException` in the `AcceptCallback` method: + +```csharp +catch (InvalidOperationException) +{ + // In .NET 9.0+, TcpListener throws InvalidOperationException when stopped + break; +} +``` + +**File**: `/CANAPE.Net/Listeners/TcpNetworkListener.cs` +**Line**: ~165 (in the `AcceptCallback` method) + +## Build and Run + +To build the solution: +```bash +dotnet build CANAPE.Core.sln -c Release +``` + +To run the CLI with the SOCKS proxy example: +```bash +cd CANAPE.Cli/bin/Release/net9.0 +dotnet exec CANAPE.Cli.dll /path/to/CANAPE.Cli.Lib/Examples/SocksProxy.csx --color +``` + +## Known Warnings + +The build produces several deprecation warnings that should be addressed in future updates: + +1. **SYSLIB0057**: X509Certificate2 constructor is obsolete - should use X509CertificateLoader +2. **SYSLIB0039**: TLS 1.0/1.1 protocols are obsolete - should use newer TLS versions +3. **SYSLIB0001**: UTF7Encoding is obsolete - should use UTF-8 +4. **NU5048**: PackageIconUrl is deprecated - should use PackageIcon + +These warnings don't prevent the code from working but should be addressed for better security and future compatibility. + +## Testing + +The migration was tested by: +1. Building the entire solution successfully +2. Running the SOCKS proxy example without errors +3. Verifying the TCP listener starts and accepts connections properly + +## Date + +Migration completed: October 12, 2025 diff --git a/README.md b/README.md index 669fcbc..993ea92 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # CANAPE.Core - (c) James Forshaw 2017 A network proxy library written in C# for .NET Core based on CANAPE. Licensed under GPLv3. -It should work on any platform with .NET Standard support 2.0, so .NET Core 2.0.5 and .NET Framework 4.7.1 on Windows, Linux and -macOS should be suitable as well as recompiling for .NET framework and Mono. +This version has been updated to target .NET 9.0. -To use either compile with Visual Studio 2017 with .NET Core support or from the command line do the -following (replace netcoreapp3.0 with netcoreapp2.0 if using 2.X framework): +To use either compile with Visual Studio with .NET 9.0 SDK support or from the command line do the +following: -```cd CANAPE.Core -dotnet build CANAPE.Cli/CANAPE.Cli.csproj -c Release -f netcoreapp3.0 -cd CANAPE.Cli/bin/Release/netcoreapp3.0 +``` +dotnet build CANAPE.Cli/CANAPE.Cli.csproj -c Release +cd CANAPE.Cli/bin/Release/net9.0 dotnet exec CANAPE.Cli.dll Examples/SocksProxy.csx --color ``` \ No newline at end of file