Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / March 2007

Tip: Looking for answers? Try searching our database.

Create IL Stream from source code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Rivers - 07 Mar 2007 00:13 GMT
Hi

Does anybody know a way to create an IL stream from source code?

I am trying to create a DynamicMethod object ideally from CSharp
source code

using GetDynamicILInfo it is possible to pass raw IL to define the
method body

maybe there is a way to extract IL from a .netmodule file ?

John
Barry Kelly - 07 Mar 2007 18:25 GMT
> Does anybody know a way to create an IL stream from source code?
>
[quoted text clipped - 3 lines]
> using GetDynamicILInfo it is possible to pass raw IL to define the
> method body

MethodBase.GetMethodBody() returns MethodBody, which has various methods
and properties, such as 'GetILAsByteArray()' and 'LocalVariables' etc.

-- Barry

Signature

http://barrkel.blogspot.com/

John Rivers - 15 Mar 2007 00:29 GMT
Thanks for your reply

Unfortunately I can only call
MethodBase.GetMethodBody() and GetILAsByteArray()
on a loaded assembly
which is what I am trying to avoid
as you can not unload dot net DLL

> > Does anybody know a way to create an IL stream from source code?
>
[quoted text clipped - 10 lines]
>
> --http://barrkel.blogspot.com/
Barry Kelly - 15 Mar 2007 02:10 GMT
> Thanks for your reply
>
[quoted text clipped - 3 lines]
> which is what I am trying to avoid
> as you can not unload dot net DLL

You could do it in another AppDomain, and marshal the array across, no?

That way, you can unload the other AppDomain and the assemblies in it.

-- Barry

Signature

http://barrkel.blogspot.com/

John Rivers - 15 Mar 2007 08:43 GMT
That is a very good idea *-)

At last my scripting engine will work ...

- pass Source code to method in DLL in new AppDomain
- method compiles and returns IL bytecode as byte[]
- Unload AppDomain
- create DynamicMethod with returned bytecode

Thanks Barry

> > Thanks for your reply
>
[quoted text clipped - 11 lines]
>
> --http://barrkel.blogspot.com/
John Rivers - 15 Mar 2007 18:28 GMT
Hi Barry

I have written the scripting engine as you suggested.

And that approach is working fine

Now I am getting stuck problems such as:

"Common Language Runtime detected an invalid program."
"Bad method token."

I have success with methods such as:

public void Test() {
}//method

and this one worked temporarily:

public int Test() {
return 3;
}//method

but not with such exotic methods as:

public string Test(string a, string b) {
return a + b;
}//method

this one is interesting:

public string Test() {
return "hello";
}//method

the string literal is not included in the method body IL
so that can never work ...

and some signature problems solved with:

SignatureHelper sh = SignatureHelper.GetLocalVarSigHelper();
dii.SetLocalSignature(sh.GetSignature());

I am getting the impression that the IL has to be "rebound" a bit like
rebasing a DLL

Have you had any success?

John

> That is a very good idea *-)
>
[quoted text clipped - 24 lines]
>
> - Show quoted text -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.