Been scratching my head with this one for a few hours. I've got a handful of CLR DLLs which work ok, but this most recent is giving me a few headaches. Any insight will be helpful.

I've tried several things, such as various string lengths (including nvarchar(MAX)), plus also checked [mapping docs](https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration-database-objects-types-net-framework/mapping-clr-parameter-data?view=sql-server-ver16)

Error Message:

> 
> CREATE FUNCTION for "CleanFile" failed because T-SQL and CLR types for return value do not match.
> 
> 
> 

SQL Command I'm running:

```
CREATE FUNCTION [dbo].[CleanFile](@filename nvarchar(500), @runmode int)
RETURNS nvarchar(500) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [sqlFileClean].[sqlFileClean].[CleanFile]

```

C# DLL:

```
//usings removed for visibility
public class sqlFileClean
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString CleanFile(
            SqlString FileName,
            SqlInt32 RunMode)
    {
        try
        {
           //Code removed here for visibility
        }
        catch (Exception ex)
        {
            // return any unhandled error message
            return ex.Message;
        }
    }

};

```