Troubleshooting Guide: SQL Server Error 6576 – Type Not Public in Assembly
Why This Error Happens
Error 6576 occurs when SQL Server attempts to reference or bind a CLR type from a SQLCLR assembly, but the specified class or structure is declared with an access modifier other than public (such as internal, private, or protected) in the source code. SQL Server’s CLR integration requires that any type exposed as a user-defined type, aggregate, or table type be explicitly marked public so the SQL Server hosting process can instantiate and serialize it correctly. This typically stems from a developer oversight during assembly compilation, an incorrect build configuration, or deploying a debug/internal build of the assembly to production by mistake.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Assembly and Type
- Note the exact assembly name and type name (
%lsand%ls) from the error message text in SSMS or the SQL Server error log. - Run the following query to confirm the assembly is registered in the target database:
SELECT * FROM sys.assemblies WHERE name = 'YourAssemblyName';
SELECT * FROM sys.assembly_types WHERE assembly_id = (SELECT assembly_id FROM sys.assemblies WHERE name = 'YourAssemblyName');
- Locate the corresponding
.csor.vbsource file in your Visual Studio solution for that type.
Step 2: Correct the Access Modifier in Source Code
- Open the class or struct definition in Visual Studio 2022/2025.
- Change the declaration from
internal class MyTypeorclass MyType(default internal) topublic class MyType. - If it is a user-defined aggregate or UDT, ensure the
[Serializable]and[SqlUserDefinedType]attributes are also present alongside thepublickeyword. - Rebuild the project in Release mode via
Build > Rebuild Solution.
Step 3: Redeploy the Corrected Assembly
- Drop the old assembly and any dependent objects first:
DROP TYPE IF EXISTS dbo.YourTypeName;
DROP ASSEMBLY IF EXISTS YourAssemblyName;
- Re-register the newly compiled DLL:
CREATE ASSEMBLY YourAssemblyName
FROM 'C:\Deploy\YourAssembly.dll'
WITH PERMISSION_SET = SAFE;
- Recreate any UDTs, UDFs, or stored procedures that depend on this assembly.
Step 4: Validate CLR Configuration on the Server
- Confirm CLR integration is enabled on your Windows Server 2025 / Windows 11 instance:
sp_configure 'clr enabled';
- If it returns
0, enable it:
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
- Restart the SQL Server service via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVERif configuration changes were applied.
Alternative or Verification Steps
- After redeployment, verify the type is accessible by running a sample query or function call that references the type directly; a successful execution with no Error 6576 confirms the fix.
- If the error persists, use ILSpy or dotPeek to decompile the deployed DLL and confirm the actual compiled bytecode reflects the
publicmodifier—sometimes a stale DLL is redeployed instead of the newly built one.