Solved

Embed a hashtable into a compiled assembly

Posted on 2004-04-07
5
461 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_
Comment Utility

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

Author Comment

by:gregasm
Comment Utility
me too. I bet esteban_felipe knows. haha
0
 
LVL 8

Author Comment

by:gregasm
Comment Utility
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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

14 Experts available now in Live!

Get 1:1 Help Now