Troubleshooting Guide: Error 11622 – CREATE ASSEMBLY Must Be FROM a Constant Binary Expression
Why This Error Happens
This error occurs because SQL Server 2025 requires the CREATE ASSEMBLY statement to reference a literal binary value, a variable, or a parameter that evaluates to a constant — it cannot accept the output of a function call, subquery, or any dynamically computed expression directly in the FROM clause. This typically happens when developers attempt to pass the result of OPENROWSET(BULK...) combined with inline conversions, or try to concatenate/manipulate the binary stream on the fly rather than loading it into a variable first. It can also surface if the assembly source path is being resolved through a non-deterministic function (such as a custom CLR function or a system function returning varbinary) instead of a straightforward file path string or hardcoded binary literal.
Step-by-Step Resolution Guide
Step 1: Isolate the Binary Source Into a Variable
- Do not pass expressions directly into
CREATE ASSEMBLY ... FROM. - Load the binary first using a
DECLAREandSELECTinto avarbinary(max)variable:
DECLARE @AssemblyBinary varbinary(max);
SELECT @AssemblyBinary = BulkColumn
FROM OPENROWSET(BULK 'C:\Assemblies\MyAssembly.dll', SINGLE_BLOB) AS x;
Step 2: Execute CREATE ASSEMBLY Using the Constant Variable
- Reference the variable directly in the
FROMclause — never nest theOPENROWSETor function call inline. - Correct syntax:
CREATE ASSEMBLY MyAssembly
FROM @AssemblyBinary
WITH PERMISSION_SET = SAFE;
- Avoid syntax like
CREATE ASSEMBLY MyAssembly FROM (SELECT ... ), which triggers Error 11622.
Step 3: Verify File Path and Permissions if Using File-Based Loading
- If loading directly via file path string (e.g.,
FROM 'C:\Assemblies\MyAssembly.dll'), ensure the path is a plain string literal, not a concatenated expression. - Confirm the SQL Server service account has Read access to the folder:
- Right-click the folder in Windows Explorer → Properties → Security tab.
- Add the SQL Server service account (e.g.,
NT Service\MSSQLSERVER) with Read permissions. - Restart the SQL Server service via SQL Server Configuration Manager if permissions were just applied.
Step 4: Check CLR Integration and Strict Security Settings
- Ensure CLR integration is enabled:
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
- On SQL Server 2025 with CLR Strict Security enforced, make sure the assembly is signed or added to a trusted assemblies list:
EXEC sp_add_trusted_assembly @hash, @description;
Alternative or Verification Steps
- Run
SELECT * FROM sys.assemblies;after creation to confirm the assembly registered successfully without errors. - If the error persists, try creating the assembly using a static binary literal (
0x4D5A9000...) as a quick isolation test to confirm the issue lies in how the binary expression is being passed, not in the assembly file itself.