我可以像 MSSMS 生成的程序集脚本一样从流创建程序集吗?
我需要从位于 SQL Server 无权访问的目录中的 DLL 创建程序集。
不过,程序集安装程序确实可以访问程序集。
所以我的问题是:我可以读取程序集并从读取的流中生成一个创建吗?
谢谢。
最佳答案
我想我明白了..
我正在使用来自 this post 的 Tomalak 的字节数组到十六进制方法.
private string getAssemblyAsHex(string asmPath)
{
using (BinaryReader br = new BinaryReader(File.OpenRead(asmPath)))
{
byte[] buff = new byte[br.BaseStream.Length];
br.Read(buff, 0, buff.Length - 1);
return ByteArrayToString(buff);
}
}<p></p>
<pre><code> private static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
</code></pre>
<p></p>
然后我将这个字符串连接到 CREATE ASSEMBLY 语句。编写代码时考虑了一个小型 DLL 程序集。
关于c# - SQL Server 2005 使用 C# 从流创建程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2055788/