ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Microsoft Related  >>  Dot Net  >>  Dot Net General
 
 


 

 
 Dot Net Framework interview questions  Dot Net Framework Interview Questions
 Dot Net Remoting interview questions  Dot Net Remoting Interview Questions
 Dot Net WindowsForms interview questions  Dot Net WindowsForms Interview Questions
 Dot Net General interview questions  Dot Net General Interview Questions
 Dot Net AllOther interview questions  Dot Net AllOther Interview Questions
Question
How will u load dynamic assembly? How will create assemblies
at run time?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How will u load dynamic assembly? How will create assemblies at run time?
Answer
# 1
You can create an assembly at runtime in the following 
way...

The following example creates an assebly, class within it 
and also defines the main method.

You can use dynamic invocation methods to execute the 
assembly.

Make use of System.Reflection and System.Reflection.Emit 
namespaces. Hope you find this useful.

public static void Main()
        {
            // 1.
            // Create a new dynamic assembly 
            AssemblyName assemblyName = new AssemblyName
("DynamicHelloWorld");
            AssemblyBuilder dynamicAssembly = 
AppDomain.CurrentDomain.DefineDynamicAssembly(
                                              assemblyName,
                                              
AssemblyBuilderAccess.RunAndSave);
            
            // 2.
            // Create a module inside the assembly 
            ModuleBuilder dynamicModule = 
dynamicAssembly.DefineDynamicModule(
                                          
assemblyName.Name, 
                                          "DynamicHelloWorld
.exe");
            
            //3. 
            // Create a type inside the module 
            TypeBuilder programType = 
dynamicModule.DefineType(
                                      "DynamicHelloWorld.Pro
gram",
                                      TypeAttributes.Class 
| TypeAttributes.Public);
            
            // 4. 
            // Add a method 
            MethodBuilder main = programType.DefineMethod(
                                "Main",
                                MethodAttributes.Public | 
MethodAttributes.Static,
                                null,
                                null);
            
            // 5. 
            // Add the IL for the method. The IL is 
equivalent to  
            // Console.WriteLine("Hello, world!"); 
            Type console = typeof(Console);
            MethodInfo writeLine = console.GetMethod(
                                   "WriteLine",
                                   new Type[] { typeof
(string) });
            
            ILGenerator il = main.GetILGenerator();
            il.Emit(OpCodes.Ldstr, "Hello, world!");
            il.Emit(OpCodes.Call, writeLine);
            
            // 6. 
            // Set the return value to 0 
            //il.Emit(OpCodes.Ldc_I4_0);
            //il.Emit(OpCodes.Ret);
            
            // 7.
            // Now we're done, materialize the type 
            programType.CreateType();
            
            // 8.
            // Set the program's entry point to the Main 
method 
            dynamicAssembly.SetEntryPoint(main, 
PEFileKinds.ConsoleApplication);
            
            // 9.
            // Save the assembly 
            dynamicAssembly.Save("DynamicHelloWorld.exe");

            Console.Write("Dynamic Assembly Emitted...");
}
 
Is This Answer Correct ?    2 Yes 0 No
Ruena
 

 
 
 
Other Dot Net General Interview Questions
 
  Question Asked @ Answers
 
Write code for fetch record nos 15 to 25 from a dataset containing 50 records? C-Squared-Systems4
What are object pooling and connection pooling and difference? TCS3
How to find methods of a assembly file (not using ILDASM) Reflection  1
What is different between Web User Control and Web Custom Control?  1
If we want to write a Windows service that cannot be paused, only started and stopped. How to accomplish that?  1
Difference between Debugging and tracing in .net  1
why .net does not support multiple inheritance? Microsoft2
Why DLL files are needed. & how They are Created in DOTNET?  1
How do you give a Windows service specific permissions?  1
What are the providers available with VS.NET ? TCS2
How to write an MMC snap-in for my Windows service?  1
why do you want to join deloitte, where do you exactly fit in. Deloitte1
What are the contents of assembly? Ksb4
What is Custom attribute? How to create? Namespace? If I'm having custom attribute in an assembly, how to say that name in the code? What is Reflection in .NET? Accenture2
How can you see which services are running on a Windows box?  1
What is UDDI and how to register a web service ? TCS2
How will u load dynamic assembly? How will create assemblies at run time?  1
How many languages .NET is supporting now? IBS16
What is the Difference between directcast and ctype? Wipro3
differance between checkbox and rediobutton in vb.net?  1
 
For more Dot Net General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com