简体   繁体   中英

Resource exception in DLL

I have a Windows Forms Application that compiles and runs perfectly.

I have converted this to a DLL by creating a new DLL project and linking the existing forms and classes to the new project.

The DLL project compiles, but gets stuck at runtime when it gets to anything got to do with a resource, like the form's icon or imagelist.

It throws an error:

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

on the following line of code:

this.LargeImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("LargeImageList.ImageStream")));

Do I have to change how the icons and images are stored for the DLL to work correctly?

As you changed the name of the assembly / type of the application, you need to fix the way how you handled your resources and how the resourcess were been referred.

You have to access the specific assembly and you can read resources on it.

Stream stream = yourAssembly.GetManifestResourceStream(myResourceName);

当我将所有链接的文件复制到新的DLL项目的项目文件夹中,然后将它们添加到项目中而不是将它们链接到原始项目文件夹中的文件时,它起作用了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM