title: Creating .NET Framework v.2.0 assembly in SQL Server 2012
body: <p>I'm trying to access Active Directory through SQL Server 2012. My inspiration sources are:</p>
  
  <p><a href="http://blogs.msdn.com/b/ikovalenko/archive/2007/03/22/how-to-avoid-1000-rows-limitation-when-querying-active-directory-ad-from-sql-2005-with-using-custom-code.aspx" rel="nofollow">http://blogs.msdn.com/b/ikovalenko/archive/2007/03/22/how-to-avoid-1000-rows-limitation-when-querying-active-directory-ad-from-sql-2005-with-using-custom-code.aspx</a></p>
  
  <p>and</p>
  
  <p><a href="http://www.pawlowski.cz/2011/04/querying-active-directory-sql-server-clr/" rel="nofollow">http://www.pawlowski.cz/2011/04/querying-active-directory-sql-server-clr/</a></p>
  
  <p>Both of them are using assembly to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll.</p>
  
  <p>When I try to create this assembly using this code:</p>
  
  <pre><code>CREATE ASSEMBLY [System.DirectoryServices]
  FROM 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll'
  WITH PERMISSION_SET = UNSAFE
  GO
  </code></pre>
  
  <p>then it fails with this message:</p>
  
  <blockquote>
    <p>Assembly 'System.DirectoryServices' could not be installed because existing policy would keep it from being used.</p>
  </blockquote>
  
  <p>I've tried create assembly on v4.0 using this code:</p>
  
  <pre><code>CREATE ASSEMBLY [System.DirectoryServices]
  AUTHORIZATION [dbo]
  FROM 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.DirectoryServices.dll'
  WITH PERMISSION_SET = UNSAFE
  GO
  </code></pre>
  
  <p>and it was successful. After this I've tried alter this new assembly using this code:</p>
  
  <pre><code>ALTER ASSEMBLY [System.DirectoryServices]
  FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll'
  </code></pre>
  
  <p>and it fails with this message:</p>
  
  <blockquote>
    <p>Alter assembly from 'system.directoryservices, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=msil' to 'system.directoryservices, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=msil' is not a compatible upgrade.</p>
  </blockquote>
  
  <p>Anyone have a idea how to create assembly on .NET Framework .dll in version 2.0?</p>