Why This Error Happens
Error 4119 occurs when a column defined with a CLR user-defined type (UDT) attempts to bind a default value to a property that lacks a public, accessible setter in the compiled assembly. SQL Server’s CLR integration engine requires strict adherence to serialization and mutator contracts (IBinarySerialize), and if the assembly was compiled with read-only properties, internal setters, or mismatched attributes, the engine cannot invoke the setter during default value assignment. This is often compounded by an outdated or corrupted CLR assembly registered in the database that no longer matches the metadata SQL Server expects.
Step-by-Step Resolution Guide
Step 1: Verify the CLR Assembly and Property Definitions
- Open the source project for the CLR UDT and confirm every property intended to hold a default value has a
public set;accessor. - Check that the class is decorated correctly with
[Serializable]and[SqlUserDefinedType(Format.Native)]orFormat.UserDefinedas appropriate. - Rebuild the assembly in Visual Studio targeting the .NET version supported by SQL Server 2025 (typically .NET 8 LTS runtime compatibility mode).
Step 2: Re-register the Assembly in SQL Server
- Drop the existing assembly reference using:
DROP TYPE dbo.YourCLRType;
DROP ASSEMBLY YourAssemblyName; - Re-deploy the updated DLL with:
CREATE ASSEMBLY YourAssemblyName FROM 'C:\SQLAssemblies\YourAssembly.dll' WITH PERMISSION_SET = SAFE; - Recreate the type:
CREATE TYPE dbo.YourCLRType EXTERNAL NAME YourAssemblyName.[YourClassName];
Step 3: Adjust the Table Definition to Avoid Inline Default Binding
- Instead of assigning a default directly in the column property setter, apply the default at the table level using a constraint:
ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_YourColumn DEFAULT (CONVERT(dbo.YourCLRType, '<serialized_value>')) FOR YourColumn; - Ensure the serialized string format matches the UDT’s
Parse()method output exactly, as SQL Server uses this method to construct the default instance.
Step 4: Enable CLR Integration and Confirm Trust Settings
- Run
EXEC sp_configure 'clr enabled', 1; RECONFIGURE;to ensure CLR execution is active on the instance. - On Windows Server 2025 / Windows 11, verify the assembly is signed and trusted, or mark the database as trustworthy with:
ALTER DATABASE YourDB SET TRUSTWORTHY ON; - Restart the SQL Server service via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVERto clear cached assembly metadata.
Alternative or Verification Steps
- Run
SELECT * FROM sys.assembly_types WHERE name = 'YourCLRType';to confirm the type registered correctly without errors, then insert a test row relying on the default value. - If the error persists, bypass the CLR default entirely by handling default value logic in application code or via an
INSTEAD OF INSERTtrigger that explicitly constructs the CLR object before insertion.