Solving the SQLCLR assembly registration error 6505, “Cannot find Type”
Posted: (EET/GMT+2)
If you have developed an SQLCRL function with .NET and C#, and you then try to register your TVF function, you will run into the following error message:
Msg 6505, Level 16, State 2, Procedure FN_MyFirstTestFunction, Line 1 [Batch Start Line 18] Could not find Type 'MyFirstTestFunction' in assembly 'SqlClrFunctionTest'.
The problem usually is that you don't fully qualify your class name with the namespace it is in. So in your CREATE FUNCTION statement, specify the full name of the class as the second part of the assembly name, like this:
CREATE FUNCTION FN_MyFirstTestFunction() RETURNS TABLE ([Id] INT, [Message] NVARCHAR(100)) AS EXTERNAL NAME SqlClrFunctionTest.[SqlClrFunctionTest.MyFirstTestFunction].InitMethod
Here, the fully qualified name of "SqlClrFunctionTest.MyFirstTestFunction" points to the class correctly. Here is the corresponding C# definition:
using Microsoft.SqlServer.Server;
namespace SqlClrFunctionTest
{
public class MyFirstTestFunction
{
...
Hope this helps!