cra*_*gal 3 c# resources assemblies stream
我有一部分像这样的代码
Assembly myAssembly = Assembly.GetExecutingAssembly();
string[] names = myAssembly.GetManifestResourceNames();
foreach (string file in names)
{
if (file.EndsWith(".dtd"))
{
// attach to stream to the resource in the manifest
dtdStream = myAssembly.GetManifestResourceStream(file);
MessageBox.Show(dtdStream.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
我有我的Resources文件夹下的所有dtd文件.它有构建类型嵌入式资源.
现在,当我调试代码时,我收到一个显示System.IO.UnmanagedMemoryStream的消息框
但我想要一个Managed MemoryStream?
我的代码有什么问题?
谢谢...
资源被编译为程序集(EXE或DLL)的一部分,这意味着它们在OS启动进程时被加载到非托管内存中.这就是为什么返回的任何流GetManifestResourceStream必须是非托管(类型UnmanagedMemoryStream)的原因.
无论如何,这有什么问题?接口MemoryStream和UnmanagedMemoryStream基本相同的,它只是(隐藏)的功能,不同的,它不应该有任何后果你的.