Cannot assign image in button in windows application - c#

I am getting this error in my windows application. I have made build action " embedded resource and also make access modifier of image public. But still I am getting bellow error.
Please help me out with this error.
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure OPDManagmentSystem.Properties.Resources.resources was correctly embedded or linked into assembly OPDManagmentSystem at compile time, or that all the satellite assemblies required are loadable and fully signed.

When I copied over files, and rebuilt a new VS2008 project, there was no hierarchical relationship in Visual Studio Solution Explorer for the resource file. For example, ExceptionMessage.resx and ExceptionMessage.Designer.cs were at the same level; whereas normally the Designer.cs file is indented under the .resx file.
So what I did was create a new .resx file, and carefully copy over using NotePad and filemerge programs, pieces of the .resx file and .cs file. Then it worked fine...

Related

Invalid .resx file after renamed namespace

Consider the following situation:
In my Windows Forms appliation I have a form.
That form has a .resx file.
The form makes use of a class ("OtherClass") from another assembly ("Other.dll").
"Other.dll" is built in the same VisualStudio 2010 solution as the main application
(just a separate project in the same solution).
In the main project (the Windows Forms application) I have properly
added a reference to the "Other.dll" project.
Everything works well (as expected).
Now I need to change the namespace of the type contained in "Other.dll" from "Old.Namespace" to "New.Namespace":
In VS2010, I bring up the Properties window of the "Other.dll"
project
I change the namespace in the "Default namespace" text box from "Old.Namespace" to
"New.Namespace"
I change namespaces in related .cs files accordingly
I rebuild the modified "Other.dll" project. No errors. The modified "Other.dll" is produced OK.
Now comes the problem:
When I after this rebuild the whole solution, the compiler stops and reports that the .resx file of the form is invalid:
"Invalid Resx file. Could not load type Old.Namespace.OtherType, Other, Version 1.0.0.0, Culture=neutral, PublicKeyToken=null which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 1521, position 5"
Clearly, the .resx file still references the type with the old namespace from somewhere. That "somewhere" appers to be from inside the binary section of the .resx file!
Question:
How can I make the .resx understand that it must now reference the new type (with the changed namespace)?
Please help, I really don't know how to proceed here...
I've had the same problem and the solution was to remove the data sections from the resx file
I too had the same problem, and after trying several other options I followed Stefania Mereut's advice and deleted the data sections from the resx file. When I re-added the resources, it apparently rewrote the data sections correctly.
I had this problem when I was updating a reference to a new version of a dll. In my case, the references had the option "specific version" = true. In that case, it is not possible to deserialize an old version of a class inside the res file because it contains the version of the old class on it.
I changed the option on my refereces "specific version" from "true" to "false" and everything worked again.
You need to open the resx file manually and change the type name of this binary resource to the new correct type name. I'm guessing this is a non-standard (i.e. not a string or image) resource that's been added manually to the resx file directly.
I believe these can only be viewed in the 'Other' section of the ResX editor - they can't be added through it.

VS 2008 does not understand .resource files

I'm trying to add globalization support to my C# application.
According to MSDN, there should be one embedded resource file for neutral culture and satellite DLLs with resource files for other cultures.
I've created 2 satellite DLLs without any problems and got my app to automatically load right one using ResourceManager. But I can't embed default neutral culture resource file into my executable. When I remove all satellite DLLs or set culture to some culture I don't have satellite DLL for, I get exception "Could not find any resources appropriate for the specified culture or the neutral culture." when application attempts to create ResourceManager.
It looks like VS 2008 does not include my .resource file into main assembly. I've tried different ways to get resource file embedded: compiling it by resgen.exe from text file and adding it to the project; changing its name to add second .resources extension; creating .resx file with same name; etc. And I still don't see the way to get resource file embedded and used by ResourceManager - I'm having same exception.
What is the right way to add default neutral culture resource file to application in VS 2008 ?
Ok, I've solved this problem by little 'hack'.
I've compiled resource file using resgen.exe, as described in MSDN, then added it to the project, renamed it to "resources" and changed build action from "None" to "Embedded resource".
Looks like VS 2008 adds "." as prefix to resource file name. So if u will name your resource file ".resources" it won't work cuz actually VS will name it "..resources".
in .Net the resource files are using the .resx extension. To have it 'embedded' in your project, make sure the "Custom Tool" in the properties page of the .resx file is using the "ResXCodeGenerator"
Hope this helps,

C#/.Net: What are the best practices for setting ResXResourceReader's basepath?

I am working on a Windows Forms application in C#/.Net. I want to use a resource file that contains translations of my strings. My my project in visual studio I have the following hierarchy:
Project
CS files ...
Resources\
resource.en-US.resx
I am trying to read in the resource file as follows:
m_ResourceReader = new ResXResourceReader("resources/resource.en-US.resx");
When I run this project, Visual Studio seems to look for the resources folder in the bin/Debug output folder of my project.
My questions are:
What is the right way to reference a resource file?
I would like my installer to place this resource file under my application's folder under Program Files\MyApp\resources\resource.en-US.resx. What would be the way to make ResXResourceReader read it from that location.
Thanks for your help.
-Raj
There is no right way to reference a .resx file at runtime. They are design-time files, the build system translates them to satellite assemblies. And copies the resulting DLL into the en-US folder of your bin\Debug folder. And the runtime automatically finds and uses them if the current culture is set to en-US.
I suppose you can get .resx reading going, but you'll get no help from the IDE or the build system to do so. I'd have to recommend you avoid fighting the machine.

Include and Reference Resource File from C# class

I have an image that is used in some PDF files that my C# application generates. I know how to reference the image file when it is located in my workspace, but when I compile the program, I don't see the image anywhere in the compiled directory.
Can someone tell me what happened to that file, or do I have to manually package the file along with my program when I send the program to the users? I added the image to the workspace by drag-drop to the resource directory of one of my namespaces.
Check the file's properties in Visual Studio. Have you set the CopyToOutputDirectory property to something besides Do not copy?
Hmm... I'm not sure about the whole drag-drop business, but if it's all working the resource will have been embedded into your assembly.
I suggest you have a look with Reflector - you can see the resources embedded within assemblies using that.
Have a look at the build properties for the item in Solution Explorer - in particular, if the build action is Embedded Resource then it will indeed be built into the assembly.

C# Creating a setup for multi-language

I have added multi-language using the short article below.
When you add for example German language you will have these files:
formMain.resx
formMain.de-DE.resx
formMain.Designer.cs
formMain.cs
In first file you will have resources for neutral language, like strings, images, ..
So now you need to add also resources for strings used in code. Add a new resource file and name it formMain.Strings.resx
Then i will enter name, value pair for every string that should be translated. When you add resource file then it is automatically typed because another file with name formMain.Strings.Designer.cs is automatically regenerated on every close of resx designer.
Add another resource with name formMain.Strings.de-DE.resx. Add the same Name key's from previous resource, and just change the Value with coresponding german words. Now to access created resource from the source it will be like this.
MessageBox.Show(formMain_Strings.SameStringName);
However, I have changed my to Thai language. Everything works fine when I run my app in VS.
However, as soon as I add a setup project and install on the clients machine it won't change the language to Thai and just keeps to the default language.
So I have added the resource files and the th-TH dll to the project setup. And I still get the same problem.
Packaging file 'Lang.Strings.resx'...
Packaging file 'MultiLanguage.resources.dll'...
Packaging file 'MultiLanguage.exe'...
Packaging file 'Lang.Strings.th-TH.resx'...
As everything works fine when running in visual studio. Is there something I need to do to get it to run once its been installed. All the properties for each of the file I have keep the default.
Many thanks,
=========
static void Main()
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("th-TH");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
I found the answer
Click the Setup Project in Solution Explorer and then click Add\Project Output\ . From dialog select the project for which you want to include localization (satelite) assemblies and then select Localized resources.
After the installation in the folder that I install to, I have the th-TH folder which includes the satellite assembly.
Thanks,
Try adding in this at the app's startup (if it's not there):
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;
Here is a short article discussing some of the options of how to make this work, and options for selecting the locale at runtime.
Edit after comments:
Make sure your satellite assembly is in the appropriate place, and built correctly. From that article I referenced:
"When .NET runtime starts an application it looks for a possible satellite assembly file. A satellite assembly file is a resource only assembly file that has .resources.dll extension instead of .exe ir .dll (if the main assembly is a library). Satellite assembly files always locate on a language specific sub directory of the applciation's main directory. If application file is Converter.exe then the Japanese satellite assembly file is ja\Converter.resources.dll."
There are a few things that you should check here. Check the name of the assembly. Also, make sure it's in the proper location. In your case, it should be in a th-TH subdirectory with the appropriate name under your executable. If it's there, it should be found and used properly.
Here is another good source of information about this topic.

Categories

Resources