Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将资源正确地嵌入到已编译的源代码中?_C#_Bitmap_Compilation_Embedded Resource - Fatal编程技术网

C# 如何将资源正确地嵌入到已编译的源代码中?

C# 如何将资源正确地嵌入到已编译的源代码中?,c#,bitmap,compilation,embedded-resource,C#,Bitmap,Compilation,Embedded Resource,我想用CodeDom Provider编译一些代码并添加一些资源。我的问题是正确添加资源,以便在编译后可以在另一个项目中使用它们。 我通过CompilerParameters()的方法添加资源(位图) 编译后,我使用ILSpy反编译.dll,您可以看到位图作为嵌入资源添加到项目的文件夹资源中。 现在我想在另一个项目中使用此资源 try { Assembly resourceAssembly = Assembly.LoadFrom(pathofthefirstdassembly);

我想用CodeDom Provider编译一些代码并添加一些资源。我的问题是正确添加资源,以便在编译后可以在另一个项目中使用它们。 我通过
CompilerParameters()
的方法添加资源(位图)

编译后,我使用ILSpy反编译
.dll
,您可以看到位图作为嵌入资源添加到项目的文件夹资源中。 现在我想在另一个项目中使用此资源

try
{
    Assembly resourceAssembly = Assembly.LoadFrom(pathofthefirstdassembly);
    Stream stream = resourceAssembly.GetManifestResourceStream(resourceAssembly.GetName().Name + ".Bitmap3.bmp");
    pictureBox1.Image = Image.FromStream(stream);
}
catch (MissingManifestResourceException ex)
{
    MessageBox.Show("Mistakes: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
} 
每次我想这样做的时候,程序都会停止,并说流为空

如何解决此问题,或者如何使用刚添加资源的已编译
.dll
中的资源

try
{
    Assembly resourceAssembly = Assembly.LoadFrom(pathofthefirstdassembly);
    Stream stream = resourceAssembly.GetManifestResourceStream(resourceAssembly.GetName().Name + ".Bitmap3.bmp");
    pictureBox1.Image = Image.FromStream(stream);
}
catch (MissingManifestResourceException ex)
{
    MessageBox.Show("Mistakes: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}