How to fix Error 6595 on Windows Server 2025 / Windows 11

Why This Error Happens

This error typically occurs when SQL Server’s CLR integration attempts to deserialize or hydrate a User-Defined Type (UDT) or User-Defined Aggregate, but the target property in the managed assembly is marked as readonly or lacks a public setter. This is common after a developer updates assembly code without correctly implementing the Set accessor required by the Microsoft.SqlServer.Server.SqlUserDefinedType interface. It can also surface if the assembly loaded into sys.assemblies is stale or mismatched with the client-side DLL, causing a schema/property conflict during data binding.

Step-by-Step Resolution Guide

Step 1: Verify the Assembly Source Code Permissions

  • Open the Visual Studio project (or source) associated with the specific assembly named in the error message.
  • Locate the specific property (%ls) flagged in the Event ID 6595 log.
  • Ensure the property has both a get and a set accessor. If it is intentionally read-only, ensure the Format.UserDefined serialization logic does not attempt to write to it via BinaryReader.

Step 2: Drop and Re-register the Assembly

  • Connect to the instance via SQL Server Management Studio (SSMS) 21 (compatible with SQL Server 2025).
  • Execute the following to remove the potentially corrupted or outdated version:
DROP AGGREGATE IF EXISTS [YourAggregateName];
DROP TYPE IF EXISTS [YourTypeName];
DROP ASSEMBLY IF EXISTS [YourAssemblyName];
  • Re-compile the DLL in Release mode and re-import it:
CREATE ASSEMBLY [YourAssemblyName]
FROM 'C:\SQLAssemblies\YourAssembly.dll'
WITH PERMISSION_SET = SAFE;

Step 3: Check CLR Strict Security Settings

  • Since SQL Server 2017+, clr strict security is enabled by default, which can cause silent permission conflicts that manifest as property access errors.
  • Verify the assembly is signed with a certificate or asymmetric key trusted by the server if running under SAFE or EXTERNAL_ACCESS permission sets.
  • Run the following to check current configuration:
EXEC sp_configure 'clr strict security';

Step 4: Update SQL Server 2025 Cumulative Update (CU)

  • Navigate to the Microsoft Update Catalog and check the build number of your instance.
  • Apply the latest Cumulative Update for SQL Server 2025, as early builds have known bugs with CLR Type marshalling on Windows Server 2025.
  • Restart the MSSQLSERVER service via services.msc or Restart-Service MSSQLSERVER in PowerShell after patching.

Alternative or Verification Steps

  • Verification: Run a SELECT query against the table utilizing the CLR Type to confirm the data hydrates without throwing Error 6595 in the SQL Server Error Log (Management > SQL Server Logs in SSMS).
  • Alternative: If the property must remain read-only for business logic reasons, modify the Write(BinaryWriter w) method in the assembly to bypass the specific property during the Read(BinaryReader r) deserialization cycle, preventing SQL Server from attempting the invalid write operation.