title: Error 6522 while executing a SQL CLR function on one environment whereas its working on another
body: <p>My application throws the error below while executing a CLR function (from within a SQL UDF) in a select statement in Stored Procedure. </p>
  
  <pre><code>A .NET Framework error occurred during execution of user-defined routine or aggregate "clr_name": 
  System.Exception: clr_name failed: id = 7
  System.Exception: 
     at ABC.SQLCLR.XYZ.XX.clr_name(decimal param1, integer param2)
  </code></pre>
  
  <p>Error code in SQL profiler says 6522</p>
  
  <p>Code breaks at the point where we are calling UDF that calls CLR within</p>
  
  <pre><code>SELECT ColumnId, RowId,  [OtherDB].dbo.udf_callingCLRWithin(ColumnID, RowID,[XYZ]) AS [XYZ]
  FROM tableName
  </code></pre>
  
  <p>Signature of UDF</p>
  
  <pre><code>ALTER FUNCTION [dbo].[udf_callingCLRWithin](Parameters)
  RETURNS [numeric](28, 12) WITH EXECUTE AS CALLER
  AS 
  EXTERNAL NAME &lt;AssemblyPath&gt;.[clr_*****]
  </code></pre>
  
  <p>But this happens only on one environment and not on another.
  My application and database are on different servers, that's common for all environments.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/31582881/msg-6522-level-16-warning-during-execution-of-clr-stored-procedure">this</a> similar question asked but the solution marked as answer is mostly about solutions within the CLR.</p>
  
  <p>But I don't have access to CLR code, neither I think it is an issue with code, as it is working fine on other environment.</p>
  
  <p>Things that I have verified already so far:</p>
  
  <ol>
  <li>Database calling the CLR has 'TRUSTWORTHY TRUE'</li>
  <li>I checked CLR is enabled on the server</li>
  </ol>
  
  <p>What is it that I can check on the database server to be specific, knowing the fact that CLR code is working fine on other servers? </p>
  
  <p>Does .Net Framework and SQL versions play any role ? What should I check and where?</p>