Writing .resx files with base64 data

G

Guest

Hi,
I have an application for creating resource files. The application works
with it's own file format, and can be used by a translator to create
localized content. The app can then write data back to a VS solution.

I have a problem, though. I use a ResXResourceReader for reading existing
files, then a ResXResourceWriter to write the modified files. I need to read
the old file since the writer does not support updating existing entries and
will overwrite the file.

The problem is, that in the existing files I have encountered entries which
are base64 encoded. The problem occurs with a
System.Windows.Forms.ImageListStreamer for an image list. When adding it the
writer corrupts it. This is some code to illustrate what I'm doing:

ResXResourceReader reader = null;
IDictionaryEnumerator en = null;

if (File.Exists(file)) {
reader = new ResXResourceReader(file);
en = reader.GetEnumerator();
}

using (ResXResourceWriter writer = new ResXResourceWriter(file)) {
if (reader != null) {
while (en.MoveNext()) {
// Simplified, here I just add all existing
// resources...
writer.AddResource(en.Key.ToString(), en.Value);
}
reader.Close();
}
}

Can anybody help me on this? I need to write the
System.Windows.Forms.ImageListStreamer entries without corrupting them (or
any other special entries for that matter).

Thanks,
Jakob
 
J

Jeffrey Tan[MSFT]

Hi Jakob,

Thanks very much for your feedback and thanks for your detailed sample
project.

I have tried your suggestion of commenting the line "Application.Run(new
Form1());", then uncommented the console code below:

string resXFile = @"..\..\Form1.resx";
string bakFile = Path.ChangeExtension(resXFile, ".bak");

Tester.CopyResX(resXFile, bakFile);
ComparisonResult result = Tester.CompareResXEntries(resXFile, bakFile);

Console.WriteLine(result.ToString());
Console.ReadLine();

At last, I changed the project's output type to "Console Application". But
the console output result is the same as the Winform output that: "no items
are different"

So it seems that there is no problem with the console version output on my
side. I suspect this issue is the machine specific one, I suggest you do
some test on another machine. Anyway, I will wait for your further
feedback. Thanks
====================================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jakob Bengtsson-Jensen

Hi Jeffrey,

Thank you for your time and response. I have tried it on another
machine, and am able to reproduce the behaviour reported by you; that is
the code behaves as it should, and does not corrupt the files.

On the same machine, however, I have tried running the same code in the
"real" solution. I have simply copied the Tester and ComparisonResult
classes into the Windows Forms project containing the Win Gui for the
application. Here I have very odd behaviour again. Running the code from
within Main() results in the file being copied correctly. Running the
code in the Load event of the main form makes the code produce corrupt
files.

I'm calling Application.EnableVisualStyles() in the Main() entry point.
Commenting this line out makes for correct copying, i.e. without errors,
in the Load event.

So, this code works (note, I have copied the .resx file to the root of
drive c):

static void Main(string[] args){
...

1 Application.EnableVisualStyles();
2 string resXFile = @"C:\Form1.resx";
3 string bakFile = Path.ChangeExtension(resXFile, ".bak");
4
5 Tester.CopyResX(resXFile, bakFile);
6 ComparisonResult result = Tester.CompareResXEntries(resXFile,
bakFile);
7
8 Debug.WriteLine(result.ToString());

...
}

Running lines 2-8 in the load event of the Main form results in this
being output:
There are 1 items with different values:
imageList1.ImageStream

UNLESS I also run the code in the Main method before calling:
mainForm = new MainForm();
Application.Run(mainForm);

This seems so very weird to me!?

To sum up:
Scenario 1: Run code in Main behaves OK.

Scenario 2: Run code in MainForm_Load behaves badly if
Application.EnableVisualStyles() has been called.

Scenario 3: Run code in MainForm_Load behaves OK if
Application.EnableVisualStyles() has NOT been called.

Scenario 4: Run code in Main AND MainForm_Load behaves OK regardless of
Application.EnableVisualStyles() being called.

If you have any ideas I'd be most happy to hear them. I can't send the
actual production code, but will strive to make a solution capable of
reproducing this odd behaviour.

Thanks a lot for your help so far,
Jakob Bengtsson-Jensen
 
J

Jeffrey Tan[MSFT]

Hi Jakob,

Thanks very much for your detailed problem description, it helps a lot on
the problem understanding.

Yes, it seems that your problem is very strange, which is hard to reproduce
out.
For this issue, I do not have very good suggestion for it, but you may try
to make a Application.DoEvents() call after
Application.EnableVisualStyles() to see if this works around your problem.

Anyway, I will continue monitor this thread and wait for any available
sample project.

Also, if your project is urgent and this issue is a key point to your
project, looking at the nature of this issue, it would require intensive
troubleshooting which would be done quickly and effectively with direct
assistance from a Microsoft Support Professional through Microsoft Product
Support Services. You can contact Microsoft Product Support directly to
discuss additional support options you may have available, by contacting us
at 1-(800)936-5800 or by choosing one of the options listed at
http://support.microsoft.com/default.aspx?scid=sz;en-us;top.

Thanks very much for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Oh, it seems that link is not available now, you may directly visit
http://www.microsoft.com/services/microsoftservices/supp.mspx, then choose
a support type for your issue. Also, that phone number is only for US
customer, if you are not in US, you should refer to your MSDN disk which
documented the local Microsoft PSS support phone number. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jakob Bengtsson-Jensen

Hi Jeffrey,

Thanks for this information. I will try to call Application.DoEvents().
If this does not work I will create my own writer to write the contents
to the .resx file; fortunately it's xml, so this solution will probably
be faster than trying to figure out why my current approach fails.

It is critical to my solution getting this to work, but I only need to
write strings to the resource file which simplifies the task of creating
my own writer a lot.

Thank you for you help and best regards,
Jakob
 
J

Jeffrey Tan[MSFT]

Hi Jakob,

Thanks for your feedback!

Yes, this should be valid workaround for your specific issue. Anyway, if
you need further request of figure out the root cause of the problem,
please feel free to tell me, I will work with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top