diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SqlSer.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SqlSer.cs
index c9f1536f50..3a0ccf847c 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SqlSer.cs
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SqlSer.cs
@@ -146,7 +146,7 @@ internal static SqlUserDefinedTypeAttribute GetUdtAttribute(Type t)
}
else
{
- throw InvalidUdtException.Create(t, Strings.SqlUdtReason_NoUdtAttribute);
+ throw ADP.CreateInvalidUdtException(t, nameof(Strings.SqlUdtReason_NoUdtAttribute));
}
return udtAttr;
}
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 3448abf5c3..f888874ec4 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -430,9 +430,6 @@
Microsoft\Data\DataException.cs
-
- Microsoft\Data\SqlClient\Server\InvalidUdtException.cs
-
Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs
index 8f82c1eaff..7d86c2d7ff 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs
@@ -21,12 +21,14 @@
using System.Threading.Tasks;
using System.Transactions;
using Microsoft.Data.SqlClient;
-using Microsoft.Data.SqlClient.Server;
using Microsoft.Win32;
using IsolationLevel = System.Data.IsolationLevel;
#if NETFRAMEWORK
using Microsoft.SqlServer.Server;
+using System.Reflection;
+#else
+using Microsoft.Data.SqlClient.Server;
#endif
namespace Microsoft.Data.Common
@@ -61,6 +63,26 @@ internal static class ADP
///
internal const int MaxBufferAccessTokenExpiry = 600;
+ #region UDT
+#if NETFRAMEWORK
+ private static readonly MethodInfo s_method = typeof(InvalidUdtException).GetMethod("Create", BindingFlags.NonPublic | BindingFlags.Static);
+#endif
+ ///
+ /// Calls "InvalidUdtException.Create" method when an invalid UDT occurs.
+ ///
+ internal static InvalidUdtException CreateInvalidUdtException(Type udtType, string resourceReasonName)
+ {
+ InvalidUdtException e =
+#if NETFRAMEWORK
+ (InvalidUdtException)s_method.Invoke(null, new object[] { udtType, resourceReasonName });
+ ADP.TraceExceptionAsReturnValue(e);
+#else
+ InvalidUdtException.Create(udtType, resourceReasonName);
+#endif
+ return e;
+ }
+ #endregion
+
static private void TraceException(string trace, Exception e)
{
Debug.Assert(null != e, "TraceException: null Exception");
@@ -105,7 +127,7 @@ internal static Exception ExceptionWithStackTrace(Exception e)
}
}
- #region COM+ exceptions
+#region COM+ exceptions
internal static ArgumentException Argument(string error)
{
ArgumentException e = new(error);
@@ -304,9 +326,9 @@ internal static ArgumentOutOfRangeException ArgumentOutOfRange(string message, s
TraceExceptionAsReturnValue(e);
return e;
}
- #endregion
+#endregion
- #region Helper Functions
+#region Helper Functions
internal static ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, string value, string method)
=> ArgumentOutOfRange(StringsHelper.GetString(Strings.ADP_NotSupportedEnumerationValue, type.Name, value, method), type.Name);
@@ -394,9 +416,9 @@ internal static ArgumentException InvalidArgumentLength(string argumentName, int
=> Argument(StringsHelper.GetString(Strings.ADP_InvalidArgumentLength, argumentName, limit));
internal static ArgumentException MustBeReadOnly(string argumentName) => Argument(StringsHelper.GetString(Strings.ADP_MustBeReadOnly, argumentName));
- #endregion
+#endregion
- #region CommandBuilder, Command, BulkCopy
+#region CommandBuilder, Command, BulkCopy
///
/// This allows the caller to determine if it is an error or not for the quotedString to not be quoted
///
@@ -729,9 +751,9 @@ internal static ArgumentException InvalidPrefixSuffix()
TraceExceptionAsReturnValue(e);
return e;
}
- #endregion
+#endregion
- #region DbConnectionOptions, DataAccess
+#region DbConnectionOptions, DataAccess
internal static ArgumentException ConnectionStringSyntax(int index) => Argument(StringsHelper.GetString(Strings.ADP_ConnectionStringSyntax, index));
internal static ArgumentException KeywordNotSupported(string keyword) => Argument(StringsHelper.GetString(Strings.ADP_KeywordNotSupported, keyword));
@@ -769,9 +791,9 @@ internal static ArgumentException ConvertFailed(Type fromType, Type toType, Exce
internal static ArgumentException InvalidMinMaxPoolSizeValues()
=> ADP.Argument(StringsHelper.GetString(Strings.ADP_InvalidMinMaxPoolSizeValues));
- #endregion
+#endregion
- #region DbConnection
+#region DbConnection
private static string ConnectionStateMsg(ConnectionState state)
{ // MDAC 82165, if the ConnectionState enum to msg the localization looks weird
return state switch
@@ -794,25 +816,25 @@ internal static NotImplementedException MethodNotImplemented([CallerMemberName]
TraceExceptionAsReturnValue(e);
return e;
}
- #endregion
+#endregion
- #region Stream
+#region Stream
internal static Exception StreamClosed([CallerMemberName] string method = "") => InvalidOperation(StringsHelper.GetString(Strings.ADP_StreamClosed, method));
static internal Exception InvalidSeekOrigin(string parameterName) => ArgumentOutOfRange(StringsHelper.GetString(Strings.ADP_InvalidSeekOrigin), parameterName);
internal static IOException ErrorReadingFromStream(Exception internalException) => IO(StringsHelper.GetString(Strings.SqlMisc_StreamErrorMessage), internalException);
- #endregion
+#endregion
- #region Generic Data Provider Collection
+#region Generic Data Provider Collection
internal static ArgumentException ParametersIsNotParent(Type parameterType, ICollection collection)
=> Argument(StringsHelper.GetString(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
internal static ArgumentException ParametersIsParent(Type parameterType, ICollection collection)
=> Argument(StringsHelper.GetString(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
- #endregion
+#endregion
- #region ConnectionUtil
+#region ConnectionUtil
internal enum InternalErrorCode
{
UnpooledObjectHasOwner = 0,
@@ -883,9 +905,9 @@ internal static Exception InternalConnectionError(ConnectionError internalError)
internal static Exception InvalidConnectRetryCountValue() => Argument(StringsHelper.GetString(Strings.SQLCR_InvalidConnectRetryCountValue));
internal static Exception InvalidConnectRetryIntervalValue() => Argument(StringsHelper.GetString(Strings.SQLCR_InvalidConnectRetryIntervalValue));
- #endregion
+#endregion
- #region DbDataReader
+#region DbDataReader
internal static Exception DataReaderClosed([CallerMemberName] string method = "")
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_DataReaderClosed, method));
@@ -927,9 +949,9 @@ internal static Exception InvalidXmlMissingColumn(string collectionName, string
=> Argument(StringsHelper.GetString(Strings.MDF_InvalidXmlMissingColumn, collectionName, columnName));
internal static InvalidOperationException AsyncOperationPending() => InvalidOperation(StringsHelper.GetString(Strings.ADP_PendingAsyncOperation));
- #endregion
+#endregion
- #region IDbCommand
+#region IDbCommand
// IDbCommand.CommandType
static internal ArgumentOutOfRangeException InvalidCommandType(CommandType value)
{
@@ -998,9 +1020,9 @@ internal static Exception DeriveParametersNotSupported(IDbCommand value)
=> DataAdapter(StringsHelper.GetString(Strings.ADP_DeriveParametersNotSupported, value.GetType().Name, value.CommandType.ToString()));
internal static Exception NoStoredProcedureExists(string sproc) => InvalidOperation(StringsHelper.GetString(Strings.ADP_NoStoredProcedureExists, sproc));
- #endregion
+#endregion
- #region DbMetaDataFactory
+#region DbMetaDataFactory
internal static Exception DataTableDoesNotExist(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_DataTableDoesNotExist, collectionName));
@@ -1071,17 +1093,17 @@ internal static Exception UndefinedPopulationMechanism(string populationMechanis
#else
=> throw new NotImplementedException();
#endif
- #endregion
+#endregion
- #region DbConnectionPool and related
+#region DbConnectionPool and related
internal static Exception PooledOpenTimeout()
=> ADP.InvalidOperation(StringsHelper.GetString(Strings.ADP_PooledOpenTimeout));
internal static Exception NonPooledOpenTimeout()
=> ADP.TimeoutException(StringsHelper.GetString(Strings.ADP_NonPooledOpenTimeout));
- #endregion
+#endregion
- #region DbProviderException
+#region DbProviderException
internal static InvalidOperationException TransactionConnectionMismatch()
=> Provider(StringsHelper.GetString(Strings.ADP_TransactionConnectionMismatch));
@@ -1090,18 +1112,18 @@ internal static InvalidOperationException TransactionRequired(string method)
internal static InvalidOperationException TransactionCompletedButNotDisposed() => Provider(StringsHelper.GetString(Strings.ADP_TransactionCompletedButNotDisposed));
- #endregion
+#endregion
- #region SqlMetaData, SqlTypes
+#region SqlMetaData, SqlTypes
internal static Exception InvalidMetaDataValue() => ADP.Argument(StringsHelper.GetString(Strings.ADP_InvalidMetaDataValue));
internal static InvalidOperationException NonSequentialColumnAccess(int badCol, int currCol)
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_NonSequentialColumnAccess,
badCol.ToString(CultureInfo.InvariantCulture),
currCol.ToString(CultureInfo.InvariantCulture)));
- #endregion
+#endregion
- #region IDataParameter
+#region IDataParameter
internal static ArgumentException InvalidDataType(TypeCode typecode) => Argument(StringsHelper.GetString(Strings.ADP_InvalidDataType, typecode.ToString()));
internal static ArgumentException UnknownDataType(Type dataType) => Argument(StringsHelper.GetString(Strings.ADP_UnknownDataType, dataType.FullName));
@@ -1157,9 +1179,9 @@ internal static Exception ParameterConversionFailed(object value, Type destType,
TraceExceptionAsReturnValue(e);
return e;
}
- #endregion
+#endregion
- #region IDataParameterCollection
+#region IDataParameterCollection
internal static Exception ParametersMappingIndex(int index, DbParameterCollection collection) => CollectionIndexInt32(index, collection.GetType(), collection.Count);
internal static Exception ParametersSourceIndex(string parameterName, DbParameterCollection collection, Type parameterType)
@@ -1170,16 +1192,16 @@ internal static Exception ParameterNull(string parameter, DbParameterCollection
internal static Exception InvalidParameterType(DbParameterCollection collection, Type parameterType, object invalidValue)
=> CollectionInvalidType(collection.GetType(), parameterType, invalidValue);
- #endregion
+#endregion
- #region IDbTransaction
+#region IDbTransaction
internal static Exception ParallelTransactionsNotSupported(DbConnection obj)
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_ParallelTransactionsNotSupported, obj.GetType().Name));
internal static Exception TransactionZombied(DbTransaction obj) => InvalidOperation(StringsHelper.GetString(Strings.ADP_TransactionZombied, obj.GetType().Name));
- #endregion
+#endregion
- #region DbProviderConfigurationHandler
+#region DbProviderConfigurationHandler
internal static InvalidOperationException InvalidMixedUsageOfSecureAndClearCredential()
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_InvalidMixedUsageOfSecureAndClearCredential));
@@ -1203,10 +1225,10 @@ static internal InvalidOperationException InvalidMixedUsageOfAccessTokenAndAuthe
static internal Exception InvalidMixedUsageOfCredentialAndAccessToken()
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_InvalidMixedUsageOfCredentialAndAccessToken));
- #endregion
+#endregion
#if NETFRAMEWORK
- #region netfx project only
+#region netfx project only
internal static Task CreatedTaskWithException(Exception ex)
{
TaskCompletionSource completion = new();
@@ -1451,9 +1473,9 @@ internal static IntPtr IntPtrOffset(IntPtr pbase, int offset)
}
internal static bool IsEmpty(string str) => string.IsNullOrEmpty(str);
- #endregion
+#endregion
#else
- #region netcore project only
+#region netcore project only
internal static Timer UnsafeCreateTimer(TimerCallback callback, object state, int dueTime, int period)
{
// Don't capture the current ExecutionContext and its AsyncLocals onto
@@ -1524,7 +1546,7 @@ internal static ArgumentOutOfRangeException InvalidParameterDirection(ParameterD
//
internal static Exception InvalidCommandTimeout(int value, [CallerMemberName] string property = "")
=> Argument(StringsHelper.GetString(Strings.ADP_InvalidCommandTimeout, value.ToString(CultureInfo.InvariantCulture)), property);
- #endregion
+#endregion
#endif
}
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUdtInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUdtInfo.cs
index ef2bdc4a5e..c15808bc8a 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUdtInfo.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUdtInfo.cs
@@ -4,9 +4,11 @@
using System;
using System.Collections.Generic;
-using Microsoft.Data.SqlClient.Server;
+using Microsoft.Data.Common;
#if NETFRAMEWORK
using Microsoft.SqlServer.Server;
+#else
+using Microsoft.Data.SqlClient.Server;
#endif
namespace Microsoft.Data.SqlClient
@@ -35,7 +37,7 @@ internal static SqlUdtInfo GetFromType(Type target)
SqlUdtInfo udtAttr = TryGetFromType(target);
if (udtAttr == null)
{
- throw Server.InvalidUdtException.Create(target, Strings.SqlUdtReason_NoUdtAttribute);
+ throw ADP.CreateInvalidUdtException(target, nameof(Strings.SqlUdtReason_NoUdtAttribute));
}
return udtAttr;
}
diff --git a/src/Microsoft.SqlServer.Server/InvalidUdtException.cs b/src/Microsoft.SqlServer.Server/InvalidUdtException.cs
new file mode 100644
index 0000000000..7dcecd626a
--- /dev/null
+++ b/src/Microsoft.SqlServer.Server/InvalidUdtException.cs
@@ -0,0 +1,50 @@
+// 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.
+
+using System;
+using System.Runtime.Serialization;
+
+namespace Microsoft.SqlServer.Server
+{
+ ///
+ [Serializable]
+ public sealed class InvalidUdtException : SystemException
+ {
+ private const int InvalidUdtHResult = unchecked((int)0x80131937);
+
+ internal InvalidUdtException() : base()
+ {
+ HResult = InvalidUdtHResult;
+ }
+
+ internal InvalidUdtException(string message) : base(message)
+ {
+ HResult = InvalidUdtHResult;
+ }
+
+ internal InvalidUdtException(string message, Exception innerException) : base(message, innerException)
+ {
+ HResult = InvalidUdtHResult;
+ }
+
+ private InvalidUdtException(SerializationInfo si, StreamingContext sc) : base(si, sc)
+ {
+ }
+
+ ///
+ [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
+ public override void GetObjectData(SerializationInfo si, StreamingContext context)
+ {
+ base.GetObjectData(si, context);
+ }
+
+ internal static InvalidUdtException Create(Type udtType, string resourceReason)
+ {
+ string reason = StringsHelper.GetString(resourceReason);
+ string message = StringsHelper.GetString(Strings.SqlUdt_InvalidUdtMessage, udtType.FullName, reason);
+ InvalidUdtException e = new InvalidUdtException(message);
+ return e;
+ }
+ }
+}
diff --git a/src/Microsoft.SqlServer.Server/Microsoft.SqlServer.Server.csproj b/src/Microsoft.SqlServer.Server/Microsoft.SqlServer.Server.csproj
index 7b2ec38d66..dafc9a4dbe 100644
--- a/src/Microsoft.SqlServer.Server/Microsoft.SqlServer.Server.csproj
+++ b/src/Microsoft.SqlServer.Server/Microsoft.SqlServer.Server.csproj
@@ -22,6 +22,7 @@
+
diff --git a/src/Microsoft.SqlServer.Server/Strings.Designer.cs b/src/Microsoft.SqlServer.Server/Strings.Designer.cs
index 67e310e065..ebe75538ee 100644
--- a/src/Microsoft.SqlServer.Server/Strings.Designer.cs
+++ b/src/Microsoft.SqlServer.Server/Strings.Designer.cs
@@ -77,14 +77,36 @@ internal static string ADP_NotSupportedEnumerationValue {
return ResourceManager.GetString("ADP_NotSupportedEnumerationValue", resourceCulture);
}
}
-
+
///
- /// Looks up a localized string similar to range: 0-8000.
+ /// Looks up a localized string similar to '{0}' is an invalid user defined type, reason: {1}..
///
- internal static string SQLUDT_MaxByteSizeValue {
+ internal static string SqlUdt_InvalidUdtMessage
+ {
get {
+ return ResourceManager.GetString("SqlUdt_InvalidUdtMessage", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to range: 0-8000.
+ ///
+ internal static string SQLUDT_MaxByteSizeValue
+ {
+ get
+ {
return ResourceManager.GetString("SQLUDT_MaxByteSizeValue", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to no UDT attribute.
+ ///
+ internal static string SqlUdtReason_NoUdtAttribute
+ {
+ get {
+ return ResourceManager.GetString("SqlUdtReason_NoUdtAttribute", resourceCulture);
+ }
+ }
}
}
diff --git a/src/Microsoft.SqlServer.Server/Strings.resx b/src/Microsoft.SqlServer.Server/Strings.resx
index 20c25de4ea..deb5efff24 100644
--- a/src/Microsoft.SqlServer.Server/Strings.resx
+++ b/src/Microsoft.SqlServer.Server/Strings.resx
@@ -123,6 +123,12 @@
The {0} enumeration value, {1}, is not supported by the {2} method.
+
+ no UDT attribute
+
+
+ '{0}' is an invalid user defined type, reason: {1}.
+
range: 0-8000
diff --git a/src/Microsoft.SqlServer.Server/TypeForwards.cs b/src/Microsoft.SqlServer.Server/TypeForwards.cs
index efd2f9d4a3..9b9c27afdd 100644
--- a/src/Microsoft.SqlServer.Server/TypeForwards.cs
+++ b/src/Microsoft.SqlServer.Server/TypeForwards.cs
@@ -1,5 +1,6 @@
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.SqlServer.Server.IBinarySerialize))]
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.SqlServer.Server.InvalidUdtException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.SqlServer.Server.Format))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.SqlServer.Server.SqlFacetAttribute))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.SqlServer.Server.SqlFunctionAttribute))]
diff --git a/tools/specs/Microsoft.SqlServer.Server.nuspec b/tools/specs/Microsoft.SqlServer.Server.nuspec
index 91597ca438..3c9499ffc4 100644
--- a/tools/specs/Microsoft.SqlServer.Server.nuspec
+++ b/tools/specs/Microsoft.SqlServer.Server.nuspec
@@ -14,6 +14,7 @@
Available Types:
Microsoft.SqlServer.Server.IBinarySerializer
+Microsoft.SqlServer.Server.InvalidUdtException
Microsoft.SqlServer.Server.SqlFacetAttribute
Microsoft.SqlServer.Server.SqlFunctionAttribute
Microsoft.SqlServer.Server.SqlMethodAttribute