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.
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?
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!
Related
I'm decompiling some .NET code for diagnosing an issue but the object is very large. To that end, I've been trying to see where .NET would raise the error I'm looking for by resource string as the exception type is fairly generic but the error message is specific to ultimate issue I'm looking into.
Decompiling the code, I see that it uses a string resource manager to pull out the text but without being able to match the resource key to the text, I cannot trace from the error message to the point in decompiled code.
E.g., exceptions are generated like the following in the decompiled code:
throw new ArgumentOutOfRangeException("value", SR.GetString("net_io_timeout_use_ge_zero"));
Where would I find the .NET's localized error text and associated resource key (e.g. "net_io_timeout_use_ge_zero")?
I've tried using ResHacker on System.dll and System.Net.dll (the assembly with the object I'm investigating) but both of these yield nothing. Likewise, while there's a culture subfolder of en-US under %windir%\Microsoft.NET\Framework\v4.0.30319 and the 64 equivalent but these don't show any text bar the assembly details and some icons in the System.dll
This is really PetSerAl's answer (if he posts one, I'll mark it as such) but to find the resource strings you can use ILSpy to load up the assembly and the resources can be found on the Resources node like so;
Going further, while ILSpy does list the resources, it doesn't provide a direct way to search for them. Saving saves out the compiled details which are not easily readable (there's a github request for this). In the meantime, you can select the contents the grid by selecting a single item, CTRL+A to select all, CTRL+C to copy the grid to the clipboard. From there you can paste into the likes of Excel or Notepad and search for the text you need.
I am trying to implement a feature in LogExpert https://logexpert.codeplex.com/
Since LogExpert uses a 3rd party dll for dockpanel called WeifenLuo WinFormsUI (https://github.com/dockpanelsuite/dockpanelsuite), this dll is being referenced in LogExpert.
In the WinformsUI, while coding, I am able to use
_imageButtonClose = Resources.DockPane_Close; whereby DockPane_Close is an bitmap image.
However at run time, all the objects/elements of Resources are either null, or the images are marked as an error FileNotFound exception even if the images are rightly embedded in the Resources.resx.
Any help on this, will be much appreciated.
Thanks.
Finally managed to find the issue.
There was a conflict of the language set in the assemblies. So I changed all the language to neutral in the assembly GUI of the project, and here it goes to working fine.
I have a localized WinForms application. To avoid a large number of iterations in the translation procedure, I have given our translators software to allow them to edit the .resx files directly.
This has worked great for the resource files that are not tied to UI components (Forms/Controls), but for forms and Controls the resources don't seem to be getting updated. What I mean by this, is that at design-time all resource strings are correct (Text/ToolTips et al.) and I can see the correct translations - when I run the application (debug or any other release) the translations are not being updated, why?
Thanks for your time.
Edit1. The plot thickens further. There are two buttons that are not being updated at all when I change their components (button text, tooltip or any thing governed by the underlying resource file). Lets say I change the button text from 'Lock Workbook' to 'Lock Workbook GG', then the new text shows in the designer and the .resx files (both in the .resx designer and the code behind) but when I run the code (in debug or release mode) the button text is not updated!?
If I update the button next to the button I updated above, this does change the text in the running application?? This is baking my noodle as I fail to see where the old text is being stored and why for a sub-set of buttons their component text is not getting updated!?
Any ideas are warmly welcomed!
Edit2. I have tried to delete the .suo and clean and recompile. I have also removed the troublesome form from the solution and re added it.
So that you can see this strange behavior, here is one of the problematic buttons ('Lock Workbook GG') and a normal one ('Set as Default Workbook GG').
Now at run-time I see
Maybe your build settings are wrong?
This is what I have for my dll.
I have given our translators software to allow them to edit the .resx files directly
That certainly was not a good idea. Any professional translator will know how to tackle .NET resx files. Even if they don't have any of the tooling that's traditionally used by translators, like SDL Passolo, then they would still fall back to the standard Winres.exe utility included with the SDK.
Whatever you wrote probably has a bug. Quite hard to reverse-engineer from the question what that bug might be. Other than that the .resx file for a Winforms form is quite different from the one you get from Resource File project template or the resource designer. There are lots of resource naming tricks to avoid ambiguity between the form's properties and the properties of its controls. Get a name wrong and it won't work right.
Don't write your own, at least ask them to use Winres.exe if necessary. It is free.
The bindings to the button are made in the Designer File of the related form, have you checked whether there are some issues? Try removing the code that sets the ressource and re-add it via the designer.
Probably this has something to do with the CopyLocal property. Please check if these are TRUE for these resource files. If not, set them to true, otherwise, after succesfull compilation, they are not being copied to the output directory.
This problem has left me scratching my head! I'll try to be as concise as possible.
On a high level:
The problem is that although the project works fine and the code looks good to me. Whenever I edit and build certain forms, Visual Studio re-writes the *.Designer.cs files in a way that is very undesirable.
I quite confident that these *.Designer.cs files have not been edited (especially the auto-generated portion) in the past.
In more detail:
Our project uses custom controls, some which inherit from PictureBox. On the forms where these controls are present, if I view the *.Designer.cs file, I either see that the Image property is not set, or the Image property refers to an image stored in the project's resx file like below, which is all well and good.
this.customButton.Image = global::MyProject.Properties.Resources.buttonImage;
However, if I simply modify this form by adding another control (drag another button onto the form) and build the project, Visual Studio extensively edits the MyForm.Designer.cs and MyForm.resx files, even for the existing controls on the form that were not touched. It seems that it embeds all the images needed by the controls in the MyForm.resx file and then refers to them in the MyForm.Designer.cs as follows:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MyForm));
this.customButton.Image = ((System.Drawing.Image)(resources.GetObject("customButton.Image")));
This is obviously not what I want. Why does Visual Studio want the form to use a local resource now, instead of the one embedded in the project's Resources.resx file as it was happy to do before the form was modified? If I go to the designer, view the properties of the customButton, and try to set the Image property to the image in the project resource file, it allows it, but on the next click, it will immediately revert back to the local reference embedded in MyForm.resx.
Any ideas why this is happening?
I figured this out with the help of another question
Basically, even though I've seen several recommendations to centralize your application's resources in a single assembly, this appears to be a bad choice. The VS Designer just doesn't like having to access resources external to the current assembly and while it can do so, it will also change your code to bring those resources in the current assembly by embedding them, thwarting your efforts to keep the resources in a single assembly.
I basically had to go back to keeping resources in the assembly the uses them.
I need to extract some bitmaps from an .msstyles file (the Windows XP visual style files) and I'm not sure where to start. I can't seem to find any documentation on how to do it, and the file format seems to be binary and not easily parsed. I have been able to extract the bitmap by itself using:
IntPtr p = LoadLibrary(UxTheme.ThemeName);
Bitmap bmp = Bitmap.FromResource(p, "BITMAP_NAME");
FreeLibrary(p);
However, I also need the information related to the bitmap, like the margin sizes, spacing and number of "images" per bitmap. Does anyone have any experience with this or any links to documentation that I can use?
This site claims the file format is documented though not by Microsoft.
Also found this in the Wine Crossreference.
Hope that helps!
If you want to get files out of a dll directly (remember, msstyles are dlls with another extension), you could have a look at the Anolis Project.
As for actually parsing that stuff you should look at the various tutorials on creating msstyles for information on how the various text resources in that file work.
This codeproject article seems to have exactly what you want, with a little interop involved. A managed wrapper exists and it seems rather good. The .Net WindowsForms also has the functionality built in, you might want to look at the System.Windows.Forms.VisualStyles namespace if you want simplified read only access.
You can open the msstyles using 7-zip, install it, then right click the msstyles > 7-zip, ther's 2 open inside, one as a normal button and the other with a arrow, choose the second one, then select "#"
You're now inside the msstyles, now right click to 1..mst > Open inside
You're inside the actual theme now, now just extract it's resources
Image of the msstyles open (is in spanish tho)