Troubleshooting Guide: SQL Server Error 6295 — Invalid SqlFacetAttribute Property Value
Why This Error Happens
This error occurs when a CLR user-defined type (UDT) or user-defined function registered in SQL Server 2025 contains a SqlFacetAttribute with a property value that falls outside the acceptable range defined by SQL Server’s metadata validation rules. Common culprits include negative or zero values for MaxSize, invalid Precision/Scale combinations that exceed SQL Server’s numeric limits, or incompatible settings like IsFixedLength = true combined with MaxSize = -1. This is almost always a code-level issue introduced during CLR assembly compilation rather than a server configuration problem, meaning the assembly was built with attribute values that violate SQL Server’s internal consistency checks during CREATE TYPE, CREATE ASSEMBLY, or CREATE FUNCTION operations.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Assembly and Type
- Open the full error message in SQL Server Management Studio (SSMS) or the SQL Server error log located at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG. - Note the three-part identifier in the error (database.schema.object) to locate the exact CLR type or function being registered.
- Run
SELECT * FROM sys.assembly_types WHERE assembly_id = <id>;to cross-reference the object with its source assembly.
Step 2: Inspect the SqlFacetAttribute Source Code
- Open the .NET project source code (Visual Studio 2022/2026) that defines the CLR UDT or UDF.
- Locate the
[SqlFacet(...)]attribute decoration on the class or method in question. - Check for invalid combinations such as:
MaxSizeset to0or a value less than-1.Precisiongreater than38orScalegreater thanPrecision.IsFixedLength = truepaired withMaxSize = -1(which implies MAX/unbounded length).- Correct the invalid property (e.g., change
MaxSize = -5toMaxSize = 8000).
Step 3: Rebuild and Redeploy the Assembly
- Recompile the .NET assembly using
dotnet buildor Visual Studio’s Build menu. - Drop the broken assembly in SQL Server:
DROP ASSEMBLY YourAssemblyName;(you may need to drop dependent types/functions first). - Re-register the corrected assembly:
CREATE ASSEMBLY YourAssemblyName
FROM 'C:\Deploy\YourAssembly.dll'
WITH PERMISSION_SET = SAFE;
- Re-create the CLR type or function referencing the updated assembly.
Step 4: Validate Server-Level CLR Configuration
- Confirm CLR integration is enabled on the instance:
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
- On Windows Server 2025/Windows 11, verify .NET Framework/CLR hosting components are current via Windows Update, since outdated CLR hosting binaries can sometimes cause attribute metadata to be misread.
Alternative or Verification Steps
- Verify the fix by re-running the original
CREATE TYPE,CREATE ASSEMBLY, orCREATE FUNCTIONstatement — it should complete without Error 6295, andSELECT * FROM sys.assembly_types;should list the object correctly. - If the error persists, use
ildasm.exe(IL Disassembler) on the compiled DLL to inspect the rawSqlFacetAttributemetadata and confirm no stale or cached build artifacts are being deployed instead of your corrected source.