Solved

Embed a hashtable into a compiled assembly

Posted on 2004-04-07
5
485 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
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 …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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