The .NET Framework common language runtime was shut down by user code, such as in a user-defined function or CLR type. SQL ...

The .NET Framework common language runtime was shut down by user code, such as in a user-defined function or CLR type. SQL Server is shutting down. Environment.Exit should not be used to exit the process. If the intent is to return an integer to indicate failure, use a scalar function or an output parameter instead.