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

Troubleshooting Guide: SQL Server Error 6237 – Invalid Custom Attribute on CLR Assembly Method

Why This Error Happens

This error occurs when SQL Server’s CLR integration attempts to load a managed assembly, but encounters a method decorated with a custom attribute (such as a SqlFunction, SqlProcedure, or a third-party attribute) that violates CLR integration rules—typically due to invalid parameter values, unsupported attribute properties, or incompatible data types. This is commonly caused by assemblies compiled against a different or unsupported version of the .NET runtime than what SQL Server 2025 expects, or by developer error when applying attributes meant for standalone .NET applications rather than SQLCLR contexts. Corruption in the assembly binary during deployment (via CREATE ASSEMBLY or ALTER ASSEMBLY) can also produce malformed metadata that triggers this validation failure.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Method and Attribute

  • Review the full error message to extract the exact method name, type, and assembly name referenced in the %s placeholders.
  • Open the source project (Visual Studio or your .NET IDE) and locate the method in question.
  • Check whether the custom attribute applied (e.g., [SqlFunction(DataAccess = DataAccessKind.Read)]) has any invalid or mismatched property values, such as an incorrect FillRowMethodName for table-valued functions.

Step 2: Validate the Target .NET Framework/Runtime Version

  • Confirm the assembly was built using a runtime version compatible with SQL Server 2025’s CLR host (verify via project properties in Visual Studio or the .csproj file’s <TargetFramework> tag).
  • Run the following T-SQL to check the current CLR version SQL Server is using:
SELECT * FROM sys.dm_clr_properties;
  • If there’s a mismatch, recompile the assembly targeting the supported framework version and redeploy.

Step 3: Correct and Rebuild the Attribute Declaration

  • Remove or correct the invalid custom attribute in the source code. For example, ensure SqlFacet, SqlFunction, or SqlMethod attributes only use properties valid for SQLCLR (avoid attributes/properties exclusive to ASP.NET or WCF contexts).
  • Rebuild the project in Release mode to generate a clean DLL.
  • Example fix for a common issue (invalid FillRowMethodName on a non-table-valued function):
[SqlFunction] // Remove invalid table-valued-only properties here
public static SqlString GetData(SqlInt32 id) { ... }

Step 4: Redeploy the Assembly to SQL Server

  • Drop the existing corrupted or invalid assembly:
DROP ASSEMBLY YourAssemblyName;
  • Re-register the corrected, rebuilt assembly:
CREATE ASSEMBLY YourAssemblyName
FROM 'C:\Path\To\YourAssembly.dll'
WITH PERMISSION_SET = SAFE;
  • Ensure the file path is accessible to the SQL Server service account and that the .dll isn’t blocked (right-click the file → Properties → Unblock, if downloaded from the internet).

Step 5: Check SQL Server CLR Strict Security Settings

  • On SQL Server 2025 (and inherited from 2017+), clr strict security is enabled by default, enforcing stricter validation on unsigned assemblies.
  • If the assembly is unsigned, sign it with a strong name key or certificate, then run:
sp_configure 'clr strict security', 1;
RECONFIGURE;
  • Alternatively, mark the assembly as trusted using sp_add_trusted_assembly with the correct hash value.

Alternative or Verification Steps

  • After redeploying, run CREATE FUNCTION or CREATE PROCEDURE referencing the fixed assembly method, then execute it in a test query to confirm no errors are thrown.
  • If the issue persists, use a decompiler tool (like ILSpy) on the deployed .dll to inspect the compiled metadata directly and confirm the attribute values match what SQL Server 2025’s CLR host expects—this helps rule out build/deployment pipeline corruption versus a genuine code-level attribute error.