Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to force ResXResourceWriter to use the 2.0 assembly

$
0
0

My application in running under 4.0 but I am trying to force the ResXResourceWriter to generate a resource for version 2.0.0.0 instead of 4.0.0.0:

 <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 <data name="CR_LOGO" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

   <value>

     /9j/4AAQSkZJRgABAgEAYABgAAD/7gAOQWRvYmUAZAAAAAAB/+ETPEV4aWYAAE1NACoAAAAIAAUBMgAC…. etc

So far I had no luck running the code below (possibly because the 4.0.0.0 System.Windows.Forms.dll assembly is already loaded  so the Assembly.Load is ignoring the 2.0.0.0 directive, or I’m doing something wrong.

privatevoid Form1_Load(object sender,EventArgs e)

       {

                          Image currentImage = null;

                          

                          Assembly myDllAssembly = Assembly.Load(@"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

                          System.Type MyDLLFormType = myDllAssembly.GetType("System.Resources.ResXResourceWriter");

                          ResXResourceWriter resXWritter = null;

                          try

                          {

                                 resXWritter =  (ResXResourceWriter)Activator.CreateInstance(MyDLLFormType,newstring[] {"Strings.resx"});

                              Image img =Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg");

                                  Byte[] byteBLOBData =newByte[0];

                                  using (MemoryStream ms =newMemoryStream())

                                  {

                                          img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                                          byteBLOBData = (Byte[])(ms.ToArray());

                                  }

                                  MemoryStream stmBLOBData =newMemoryStream(byteBLOBData);

                                  currentImage = Image.FromStream(stmBLOBData);

                                  resXWritter.AddResource("LOGO", currentImage);

                                  resXWritter.Generate();

                          }

                          catch (Exception ex)

                          {

                                  

                          }

                          finally

                          {

                                  resXWritter.Close();

                          }

                    

       }

Are there other options that anyone can recommend?

Thank you



Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>