Invalid .resx file after renamed namespace - c#

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.

Related

Can't add a .bin.gz file as embedded resource

If I include a .bin.gz file in a DLL as an embedded resource, it doesn't show up in the Assembly.GetManifestResourceNames() list, and cannot be loaded with Assembly.GetManifestResourceStream(). If I rename the same file to anything else, it does show up.
The .bin.gz file shows up in .csproj. I'm building a .NET Core 2.2 class library.
What's going on? Is there some kind of filter by file type that prevents certain types from being embedded?
EDIT: On further inspection. It appears that the .bin.gz resources are placed in a different .dll named [AssemblyName].resources.dll, which is placed in a "bin" folder next to the [AssemblyName].dll. Why is this and why does this not happen with other files?

How to localize WPF Application with RESX files in subdirectories

My team has some WPF projects written using XAML. We recently added a large number of local specific RESX files to each project. In order to keep things tidy, I was asked to store these files in [Project]>Localization>[locale]
Now, when we run the application on a non en-US locale, strings are pulled from the appropriate RESX file. We've tried to update Namespaces in the properties of the RESX files, as well as setting them to Public so that a resulting Designer is created.
The only way that we can get things to work is by moving the locale RESX files directly into the Project's Properties directory.
Is there anyway to update the XAML to search for locale RESX files in a subdirectory?
EDIT
XAML Codebase and Solution Explorer
I've attached an image of the problem for clarification.
Some code changes that we've tried:
1) We attempted to set the Namespace for xmlns:res="clr-namespace:[PROJECT].CoreUI.Localization"
2) Attempted to set the Namespace to xmlns:res="clr-namespace:[PROJECT].CoreUI"
3) We've also attempted to change the Custom Tool Namespace of the RESX file to match the current namespace My.Properties as well as CoreUI.Properties
We've also confirmed that the Access Modifiers for both Resources.resx and Resources.ru.resx (for example) are set to Public and that both Build Actions show "Embedded Resource"
Thanks for the help!
My colleague actually stumbled upon another post in here that we somehow missed during out countless searching:
Put translated resx files in a different folder in Visual Studio?
In short, we were thinking about making the project search down into subdirectories for the RESX files. In actuality, we need the RESX file to search for the already created designer further up in the chain.
<ItemGroup>
<EmbeddedResource Include="Localization\ar\Resources.ar.resx" >
<ManifestResourceName>$(TargetName).Properties.%(Filename)</ManifestResourceName>
</EmbeddedResource>
Entering the ManifestResourceName appears to tell the RESX file that we already have a Designer created and not to make a new one.
Thanks again for everyone's help!
You've to first include your folder in the namespace and mention project name like:
xmlns:resx="clr-namespace:Prism_Modules.MyResources;assembly=Prism_Modules"
Also you must include:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Finally, you should call values in resources as:
<dxb:BarButtonItem x:Name="menuFile" Content="{x:Static resx:Resources.mnuFile}" }" />
When moving .resx file to another folder/project, the .Designer.cs file that exposes resource members will still point to the old namespace and also Visual Studio will place it outside the .resx file.
To fix this, I simply deleted the generated .Designer.cs file and then after opening and saving .resx file, the Designer.cs file got generated with proper namespace and I could normally refer to it even from other projects. To generate .Designer.cs file for resource languages/files that have none just open .resx file and use the Access Modifier combobox and VS will create it for you.
I hope I was of any help.

Renaming C# project to map to correct configuration

I have a created a C# console application that does something. Lets say its name is SampleTest. I use a config file named App.config in it. When I build this project, it creates files like SampleTest.exe, SampleTest.exe.config, etc. This is all fine.
My friend wants to execute this executable. So rather than sending SampleTest.exe and SampleTest.exe.config, I renamed the two files to DocumentManager.exe and DocumentManager.exe.config and gave it to him.
We noticed that this way, the DocumentManager.exe is not able to use the DocumentManager.exe.config file.
Please let us know what do I need to do in Visual Studio to this SampleTest project for it to generate DocumentManager.exe and DocumentManager.exe.config?
I tried renaming the SampleTest project to DocumentManager and building it but it still generates SampleTest.exe
Renaming the Assembly
Renaming the project on it's own is likely not going to be enough for what you are trying to accomplish. You'll need to ensure that you update the name of your assembly and namespace as well, which can be done through Properties > Application > Assembly name :
Changing the assembly name will change the names of your executable and .config files generated when building the project. It's probably worth changing your default namespace as well, just to keep things consistent.
You have to rename assembly. To fix this please do the following:
Navigate to project folder and find SampleTest.csproj file.
Open that file in some text editor like Notepad++. Find elements:
<RootNamespace>SampleTest</RootNamespace>
<AssemblyName>SampleTest</AssemblyName>
Rename their values into:
<RootNamespace>DocumentManager</RootNamespace>
<AssemblyName>DocumentManager</AssemblyName>`.
4. Build your project and you will see new DocumentManager.exe.config and new DocumentManager.exe files.
Or you can change Namespace and AssemblyName trough UI by navigating to Properties > Application > Assembly Name.

Class file with .bak extension in Visual Studio 2012

Is a class file like MyClass.cs.bak used at run-time even though there is a class file by the name of MyClass.cs within the same Visual Studio project?
Both files are included in the project. The project is of Web Application type, so everything compiles into a single dll when deploying. I am not sure if during compilation, the .bak file is ignored.
I am working on a project in Visual Studio, in which some past developer has included both these files within the project.
If you click on the file in Solution Explorer and look at the Properties window, you'll see a property called "Build Action". This defines whether the file will be treated like code ("Compile"), included as a resource ("Embedded Resource"), or ignored ("None").
When a file is added to a project, the default Build Action is selected based on the file extension. For .bak files, which have no particular meaning to C# projects, the default "None" should be selected, and the file will be ignored when compiling the project.
No.
The .bak file is treated as a normal text file.
This is quite easy to test. Create a new class file, with a class name foo.
Now create a new .cs.bak file and type in the same code.
when you compile the project, you would expect a duplicate class declaration error - this does not occur.
As far as I know (and check), by default, a *.bak file is not considered as a C# class file in a VS Project. It's just another text file which doesn't complied into the assembly as a class module - Therefore, by the way, why you don't get duplicate class names declaration exception.
You can always tell to VS to treat it as a compilable c# file: Properties -> Build Action -> Compile.
It's just look like a backup (bak) source file - just for history purposes, I assume.

Cannot assign image in button in windows application

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...

Categories

Resources