问题
I am writing a plugin in C#, in which I have a user control with a linklabel
on it that controls a form that shows up like a tooltip
and a picturebox
next to the label to show the status whether or not the form is visible or hidden.
I have two images that are added as resources by the book via the Visual Studio PludingResources Designer. (I tried setting the Persistence of the images both to Linked at compile time and to embedded to solve the problem.)
The rubber meets the road in the following code:
pictureBox1.Image = SubAsst.PluginResources.SubAsst_Enabled1;
When the code execution hits this line to display the image, I get the
System.Resources.MissingManifestResourceException
exception. The exception reads:
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "SubAsst.PluginResources.resources" was correctly embedded or linked into assembly "SubtitlingAssistant" at compile time, or that all the satellite assemblies required are loadable and fully signed."
I looked all over on msdn and everywhere else I could but I could not find a solution yet. Except, if I change the code to use the built-in system icons, that works:
pictureBox1.Image = System.Drawing.SystemIcons.Information.ToBitmap();
So that is my workaround so far. However I would like to use my custom images for the plugin.
I suspect that the API does not allow image resources to be used, but this is not documented. I guess this from the fact that an icon can be imported and is displayed on the default button for the plugin.
I would appreciate any advice on this.
回答1:
Looks like some resource file is missing, check these
MSDN links
You may receive a "System.Resources.MissingManifestResourceException" error message when you access the .resources file of the form at run time A System.Resources.MissingManifestResourceException exception occurs when you try to access a localized resource
C#: What does MissingManifestResourceException mean and how to fix it?
回答2:
Here is the solution:
What was missing is the CustomToolNamespace in the properties box:
- Build action: Embedded Resource
- Copy to Output Directory: Do not copy
- Custom Tool: ResXFileCodeGenerator
- Custom Tool Namespace: [myapplicationnamespace]
The namespace matches the NameSpace of my application. As soon as I set this and rebuilt the application, the error was gone and the image displayed.
Thanks for the link in Meysam Tolouee's answer, which lead to this "off-topic" answer. Here it is definitely not off-topic, and I wish I found this earlier.
What a great tool this StackOwerflow is!
来源:https://stackoverflow.com/questions/36950232/visual-c-sharp-changing-image-on-control-gives-exception