When an AppDomain recycle occurs, most CLR module types are able to gracefully handle the situation: in-flight requests continue on the old AppDomain, new requests go to the new AppDomain, and eventually when all of the old requests are complete the old AppDomain is disposed of. This creates a more reliable and robust environment and keeps end-users from seeing exceptions when the server needs to do some housecleaning.Unfortunately, this graceful handling is not done for TVFs. If a table-valued function is running and a recycle occurs, the function will immediately be aborted. Even worse, it will send the user a confusing and very misleading exception:Msg 10316, Level 16, State 1, Line 2The app domain with specified version id (4) was unloaded due to memory pressure and could not be found.CLR TVFs are, in my experience, both the most useful -- by far -- of the available SQLCLR module types, and are probably also the most frequently used. Putting such functionality into a less robust, less reliable bucket is a major disservice to SQL Server developers and end users of SQL Server based solutions.
Operating System Language
Steps to Reproduce