Solved

Embed a hashtable into a compiled assembly

Posted on 2004-04-07
5
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …

730 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