From 947f9a76c0b184f37bc154590f6d30a6d9d5fefe Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 20 Mar 2025 17:46:49 -0500 Subject: [PATCH 1/4] Move assemblycache to common project --- .../Microsoft/Data/SqlClient/AssemblyCache.netfx.cs} | 4 ++++ 1 file changed, 4 insertions(+) rename src/Microsoft.Data.SqlClient/{netfx/src/Microsoft/Data/SqlClient/assemblycache.cs => src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs} (98%) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/assemblycache.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/assemblycache.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs index d8a877073a..b5e5e30bc1 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/assemblycache.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NETFRAMEWORK + //------------------------------------------------------------------------------ //ThisAssembly class keeps a map of the following: //AssemblyName to AssemblyID @@ -62,3 +64,5 @@ internal static SqlUdtInfo GetInfoFromType(Type t) } } } + +#endif From 2612d9529cd0f3578f5da6e70833c80e4f3d1b11 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 20 Mar 2025 17:50:39 -0500 Subject: [PATCH 2/4] Light cleanup - remove comments that make no sense anymore, make class static, couple style changes --- .../Data/SqlClient/AssemblyCache.netfx.cs | 34 +++---------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs index b5e5e30bc1..576db9fcbe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs @@ -4,42 +4,20 @@ #if NETFRAMEWORK -//------------------------------------------------------------------------------ -//ThisAssembly class keeps a map of the following: -//AssemblyName to AssemblyID -//TypeName to TypeID -//AssemblyID to AssemblyRef and State -//TypeID to TypeRef and AssemblyId -// -//Adding an assembly to this class will NOT enable users to create types from that assembly. Users should explicitly add type details and link types to assemblies. -// This class also registers for assembly resolve events so that dependent assemblies can be resolved if they are registered. -//This class does NOT know anything about assembly dependencies. It simply loads assemblies as handed over to it. -//Users can take advantage of connection pooling by tying this instance to a pooling-aware component. -//------------------------------------------------------------------------------ - using System; using System.Diagnostics; using Microsoft.Data.SqlClient.Server; namespace Microsoft.Data.SqlClient { - - internal sealed class AssemblyCache + internal static class AssemblyCache { - private AssemblyCache() - { /* prevent utility class from being instantiated*/ - } - - internal static int GetLength(Object inst) + internal static int GetLength(object inst) { - //caller should have allocated enough, based on MaxByteSize + // Caller should have allocated enough, based on MaxByteSize return SerializationHelperSql9.SizeInBytes(inst); } - //The attribute we are looking for is now moved to an external dll that server provides. If the name is changed. - //then we we have to make corresponding changes here. - //please also change sqludcdatetime.cs, sqltime.cs and sqldate.cs - internal static SqlUdtInfo GetInfoFromType(Type t) { Debug.Assert(t != null, "Type object cant be NULL"); @@ -53,10 +31,8 @@ internal static SqlUdtInfo GetInfoFromType(Type t) { return attr; } - else - { - t = t.BaseType; - } + + t = t.BaseType; } while (t != null); From 33329546c7ba4046e3bf9ff0b5701c27ced53cff Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 20 Mar 2025 17:53:42 -0500 Subject: [PATCH 3/4] Changing csproj to point to new file location --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index e1ddaa6926..bc9d372e4a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -367,6 +367,9 @@ Microsoft\Data\SqlClient\ApplicationIntent.cs + + Microsoft\Data\SqlClient\AssemblyCache.netfx.cs + Microsoft\Data\SqlClient\AssemblyRef.cs @@ -862,7 +865,6 @@ - From 4b669298d620a6f32f9fa75a10c451c09253b503 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Fri, 21 Mar 2025 18:15:32 -0500 Subject: [PATCH 4/4] Forget it, let's just get rid of AssemblyCache! --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 -- .../Microsoft/Data/SqlClient/SqlConnection.cs | 21 ++++++++- .../Data/SqlClient/AssemblyCache.netfx.cs | 44 ------------------- .../Microsoft/Data/SqlClient/SqlParameter.cs | 5 --- 4 files changed, 20 insertions(+), 53 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index bc9d372e4a..bcf4e3b193 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -367,9 +367,6 @@ Microsoft\Data\SqlClient\ApplicationIntent.cs - - Microsoft\Data\SqlClient\AssemblyCache.netfx.cs - Microsoft\Data\SqlClient\AssemblyRef.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index 3fac23d373..02eff9971d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -2725,7 +2725,7 @@ internal byte[] GetBytes(object o) internal byte[] GetBytes(object o, out Format format, out int maxSize) { - SqlUdtInfo attr = AssemblyCache.GetInfoFromType(o.GetType()); + SqlUdtInfo attr = GetInfoFromType(o.GetType()); maxSize = attr.MaxByteSize; format = attr.SerializationFormat; @@ -2743,5 +2743,24 @@ internal byte[] GetBytes(object o, out Format format, out int maxSize) } return retval; } + + private SqlUdtInfo GetInfoFromType(Type t) + { + Debug.Assert(t != null, "Type object can't be NULL"); + Type orig = t; + do + { + SqlUdtInfo attr = SqlUdtInfo.TryGetFromType(t); + if (attr != null) + { + return attr; + } + + t = t.BaseType; + } + while (t != null); + + throw SQL.UDTInvalidSqlType(orig.AssemblyQualifiedName); + } } // SqlConnection } // Microsoft.Data.SqlClient namespace diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs deleted file mode 100644 index 576db9fcbe..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AssemblyCache.netfx.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#if NETFRAMEWORK - -using System; -using System.Diagnostics; -using Microsoft.Data.SqlClient.Server; - -namespace Microsoft.Data.SqlClient -{ - internal static class AssemblyCache - { - internal static int GetLength(object inst) - { - // Caller should have allocated enough, based on MaxByteSize - return SerializationHelperSql9.SizeInBytes(inst); - } - - internal static SqlUdtInfo GetInfoFromType(Type t) - { - Debug.Assert(t != null, "Type object cant be NULL"); - - Type orig = t; - do - { - SqlUdtInfo attr = SqlUdtInfo.TryGetFromType(t); - - if (attr != null) - { - return attr; - } - - t = t.BaseType; - } - while (t != null); - - throw SQL.UDTInvalidSqlType(orig.AssemblyQualifiedName); - } - } -} - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs index 91530e5de6..f0a35b7653 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -1614,12 +1614,7 @@ internal int GetActualSize() case SqlDbType.Udt: if (!IsNull) { -#if NETFRAMEWORK - //call the static function - coercedSize = AssemblyCache.GetLength(val); -#else coercedSize = SerializationHelperSql9.SizeInBytes(val); -#endif } break; case SqlDbType.Structured: