Click here to Skip to main content
Rate this:
 
Please Sign up or sign in to vote.
See more: Embedded C# Windows compiler , +
Hi,
I am working on a localization project and having problem.
The problem is that, the resx file the user created is needed to be used at runtime.
what i mean is that, the user creates a resx file on runtime and can use it at that time quickly. So the program will not be closed or compiled again.
I create the resx file but, because i have lack of knowledge on assemblies (i researched about satellites but i could not understood well) i cannot load the resx file to the project and get embedding error. As far as i understood, i need to compile the project on runtime but how? any concept or code will help.
Thank you so much!
Posted 11-Sep-13 11:06am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Considering the resources are compiled into the running .EXE, you can't modify them. The .EXE file is locked and cannot be modified while the .EXE is running.

Another problem you have is that, under Windows Vista, 7 and 8, the Program Files folder your application is installed to is ReadOnly to normal users. They can't write to any files under Program Files without being given special permissions to do so.

If you want to see all the pain you're in for trying to get this to work (including using undocumented functions in the WinNT Kernel), try reading all of these[^]. Then you can move on to modifying the resources of a non-running .EXE, by starting here[^].
  Permalink  
Comments
tasinsahin 11-Sep-13 16:32pm
   
Thank you Dave,
I think i am not clear well.
Please correct me i make mistake.
I have more than one project in a solution and this project is compiled into an assembly and this assembly is used by another project.
I read that assemblies could be modified on runtime.
Sergey Alexandrovich Kryukov 11-Sep-13 17:32pm
   
You can modify the assembly only if its modules are not currently loaded.
I answered to this, please see my Solution 3.
—SA
Sergey Alexandrovich Kryukov 11-Sep-13 17:25pm
   
Of course, a 5.
—SA
tasinsahin 11-Sep-13 17:32pm
   
i try to use runtime created resx file and get the following error.

Localization_OO.resx.resources" was correctly embedded or linked into assembly "WindowsFormsApplication1" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Sergey Alexandrovich Kryukov 11-Sep-13 17:40pm
   
This must be related to the signed policy enforced by the CLR: if you have one assembly used in some application signed, you should sign all other assemblies. Actually, this is good for you: I suggest you make sure all assemblies (if you ever deploy it to any customer, event to an internal user) are signed. This is a very simple step, but then the assembly could not be modified (say, by a virus), can be world-unique, properly versioned, many great benefits.

I cannot see what else could be, without using your code. So, start with signing: ether sign everything, or removed all signatures (not so recommended). But you need to read about .NET globalization and localization, in particular, satellite assemblies, thread cultures and thread UI culture, fallback mechanism and the localization steps. In MSDN, this is all described in detail. Just use the keywords I suggested. This is fairly easy to understand, too.

—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

tasinsahin wrote:
I read that assemblies could be modified on runtime.
You can modify the assembly only if its modules are not currently loaded.

None of the loaded Windows executable modules can be modified.
If the assembly is not loaded, it can be modified, but this is usually (or in almost all cases) a big abuse. If an assembly is signed (highly recommended), you cannot practically modify it at all, unless you recompile it.

Overall, your idea looks like one big abuse. Don't do anything like that. Rather, I would advise your to explain your ultimate goals; in that case we will gladly try to suggest you some realy working solutions.

—SA
  Permalink  
Comments
tasinsahin 11-Sep-13 17:50pm
   
My ultimate goal is to make an application which allows the end user to create custom resource file in his own language in accordence with keys used in code, and use it on runtime. By the way , there are already resource files in some languages in the project.
Sergey Alexandrovich Kryukov 11-Sep-13 18:05pm
   
Okay, very good. Now, why not having a resource which is not embedded, but is a real separate file? It seems so obvious. The purpose of embedded resources is to prevent modifying them, and the purpose of separate configuration files is to allow people to modify then. There are some issues you should know; let me prepare the answer...
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

tasinsahin wrote:
My ultimate goal is to make an application which allows the end user to create custom resource file in his own language in accordence with keys used in code, and use it on runtime. By the way , there are already resource files in some languages in the project.
Please see my comment to this new question.

Very good, you should really use a separate file. The problem is: where to store it. If it was not modifiable on everyday basis, but modifiable only through the elevated privileges (Windows 7 "Run as Administrator"), the appropriate location is the executable directory. Please see my past answer:
How to find my programs directory (executable directory).

This case should be used only when you rarely need to modify such resource, but administrative privilege would allow to do that, only when it is really required. The typical case is some configuration information to be set and forgot.

If the resource is to be modified on a regular basis, the approach should be different. You need to put the file in a directory you reserve for your application in the per-user settings directory, of the same thing, but for all users. This is done using so called "special folder" API. This is how:
How to find my programs directory (current directory, "special folders").

If the resource has to be some kind of configuration file using, say XML (another usual option is JSON), you should better use Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please see my past answer advocating this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

Good luck,
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Web02 | 2.8.160204.4 | Advertise | Privacy
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100