Solved

Embed a hashtable into a compiled assembly

Posted on 2004-04-07
5
465 Views
Last Modified: 2012-05-04
I am generating code assemblies at runtime using the following code:

CSharpCodeProvider cscp = new CSharpCodeProvider();
                  ICodeGenerator icg = cscp.CreateGenerator();
                  StringBuilder srcStringBuilder = new StringBuilder();
                  StringWriter sw = new StringWriter(srcStringBuilder);
                  icg.GenerateCodeFromNamespace(cns, sw, null);
                  proxySource = srcStringBuilder.ToString();
                  sw.Close();

// assembly compilation
                  CompilerParameters cp = new CompilerParameters();
                  cp.ReferencedAssemblies.Add("System.dll");
                  cp.ReferencedAssemblies.Add("System.Xml.dll");
                  cp.ReferencedAssemblies.Add("System.Web.Services.dll");
                  cp.ReferencedAssemblies.Add("System.Data.dll");
                  cp.ReferencedAssemblies.Add(System.Reflection.Assembly.
                        GetExecutingAssembly().Location);
      
                  cp.GenerateExecutable = false;
                  cp.GenerateInMemory = false;
                  cp.IncludeDebugInformation = false;

                  ICodeCompiler icc = cscp.CreateCompiler();
                  CompilerResults cr = icc.CompileAssemblyFromSource(cp, proxySource);

I have a hashtable that I would like to include into this assembly so that I can retrieve the hashtable later when I reload the assembly, using reflection.

What's the best way to include this hashtable into the assembly?
0
Comment
Question by:gregasm
  • 3
5 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 10779389

I have no idea... but I'd like to find out.
0
 
LVL 8

Author Comment

by:gregasm
ID: 10779420
me too. I bet esteban_felipe knows. haha
0
 
LVL 8

Author Comment

by:gregasm
ID: 10779811
The requirements for this are actually quite simple. Just need to embed the key value pairs somewhere in the assembly so that later I can extract it using reflection. Any technique to do tthat will suffice.
0
 
LVL 8

Author Comment

by:gregasm
ID: 10780898
Ok. I've pored over the c# compiler documentation and there is a param called Win32Resource of the compiler options object. If I set that param to the string name of a resource file, I can read that and add that serialized hashtable to the manifest resource stream of the assembly. I don't want to have to do that because that would incur more disk I/O than necessary. I wish there was a way to add the resource to the assembly without having to write it to the disk first... but that Win32Resource property takes a string filename, not a memory stream. Unless it can be tricked somehow??

Well, that's the idea anyway. =]. I will see if that works tomorrow, if that doesn't work, then I will be forced to serialze the hashtable to a filestream and then persist that on disk as a separate file!

All of this just to get the webservice description and method descripts from the WSDL file, after it is compiled into the proxy using wsdl.exe. (runtime version of that compiler anyway).

Does anyone know a better way?

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10875987
Closed, 500 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now