Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Embed a hashtable into a compiled assembly

Posted on 2004-04-07
5
Medium Priority
?
509 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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