Ok, to make a long story short, I'm Emitting some MSIL from a c#
application. I know that THIS is the MSIL I want to be emitting:
//*************** *************** *************** *************** **
..method public hidebysig instance class
[System.Data]System.Data.Sql Client.SqlComma nd
Format1(class Delta.Dictionar yDispatch dispatch) cil managed
{
.custom instance void Delta.DispatchN ameAttribute::. ctor(string) = (
01 00 0B 43 4F 4D 4D 41 4E 44 5F 4F 4E 45 00 00 ) // ...COMMAND_ONE. .
// Code size 27 (0x1b)
.maxstack 4
.locals init ([0] class [System.Data]System.Data.Sql Client.SqlComma nd
rtn,
[1] class [System.Data]System.Data.Sql Client.SqlComma nd
CS$1$0000)
IL_0000: nop
IL_0001: newobj instance void
[System.Data]System.Data.Sql Client.SqlComma nd::.ctor()
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldarg.1
IL_000a: ldstr "COMMAND_ON E"
IL_000f: callvirt instance void class
Delta.DispatchF ormatter`2<clas s
[System.Data]System.Data.Sql Client.SqlComma nd,class
Delta.Dictionar yDispatch>::App lyDispatchBindi ng(!0,
class Delta.Dictionar yDispatch,
string)
IL_0014: nop
IL_0015: ldloc.0
IL_0016: stloc.1
IL_0017: br.s IL_0019
IL_0019: ldloc.1
IL_001a: ret
} // end of method TestFormatter:: Format1
//*************** *************** *************** *************** **
But THIS is the closest I can get using Reflection.Emit :
//*************** *************** *************** *************** **
..method public instance class
[System.Data]System.Data.Sql Client.SqlComma nd
Format1(class [Delta]Delta.Dictionar yDispatch A_1) cil managed
{
.custom instance void
[Delta]Delta.DispatchN ameAttribute::. ctor(string) = ( 01 00 0B 63 6F 6D
6D 61 6E 64 20 6F 6E 65 00 00 ) // ...command one..
// Code size 27 (0x1b)
.maxstack 5
.locals init (class [System.Data]System.Data.Sql Client.SqlComma nd
V_0)
IL_0000: nop
IL_0001: newobj instance void
[System.Data]System.Data.Sql Client.SqlComma nd::.ctor()
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldarg.1
IL_000a: ldstr "COMMAND_ON E"
IL_000f: callvirt instance void
[Delta]Delta.SqlDispat chFormatter::Ap plyDispatchBind ing(class
[System.Data]System.Data.Sql Client.SqlComma nd,
class [Delta]Delta.Dictionar yDispatch,
string)
IL_0014: nop
IL_0015: ldloc.0
IL_0016: stloc.1
IL_0017: br.s IL_0019
IL_0019: ldloc.1
IL_001a: ret
} // end of method Formatter::Form at1
//*************** *************** *************** *************** **
Which throws an "InvalidProgram Exception" when I try to call it. Can
anybody help me here? I'm starting to lose sleep over this. 2 1651
Never mind, I think I might have figured it out.
allfyre wrote:
Ok, to make a long story short, I'm Emitting some MSIL from a c#
application. I know that THIS is the MSIL I want to be emitting:
//*************** *************** *************** *************** **
.method public hidebysig instance class
[System.Data]System.Data.Sql Client.SqlComma nd
Format1(class Delta.Dictionar yDispatch dispatch) cil managed
{
.custom instance void Delta.DispatchN ameAttribute::. ctor(string) = (
01 00 0B 43 4F 4D 4D 41 4E 44 5F 4F 4E 45 00 00 ) // ...COMMAND_ONE. .
// Code size 27 (0x1b)
.maxstack 4
.locals init ([0] class [System.Data]System.Data.Sql Client.SqlComma nd
rtn,
[1] class [System.Data]System.Data.Sql Client.SqlComma nd
CS$1$0000)
IL_0000: nop
IL_0001: newobj instance void
[System.Data]System.Data.Sql Client.SqlComma nd::.ctor()
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldarg.1
IL_000a: ldstr "COMMAND_ON E"
IL_000f: callvirt instance void class
Delta.DispatchF ormatter`2<clas s
[System.Data]System.Data.Sql Client.SqlComma nd,class
Delta.Dictionar yDispatch>::App lyDispatchBindi ng(!0,
class Delta.Dictionar yDispatch,
string)
IL_0014: nop
IL_0015: ldloc.0
IL_0016: stloc.1
IL_0017: br.s IL_0019
IL_0019: ldloc.1
IL_001a: ret
} // end of method TestFormatter:: Format1
//*************** *************** *************** *************** **
But THIS is the closest I can get using Reflection.Emit :
//*************** *************** *************** *************** **
.method public instance class
[System.Data]System.Data.Sql Client.SqlComma nd
Format1(class [Delta]Delta.Dictionar yDispatch A_1) cil managed
{
.custom instance void
[Delta]Delta.DispatchN ameAttribute::. ctor(string) = ( 01 00 0B 63 6F 6D
6D 61 6E 64 20 6F 6E 65 00 00 ) // ...command one..
// Code size 27 (0x1b)
.maxstack 5
.locals init (class [System.Data]System.Data.Sql Client.SqlComma nd
V_0)
IL_0000: nop
IL_0001: newobj instance void
[System.Data]System.Data.Sql Client.SqlComma nd::.ctor()
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldarg.1
IL_000a: ldstr "COMMAND_ON E"
IL_000f: callvirt instance void
[Delta]Delta.SqlDispat chFormatter::Ap plyDispatchBind ing(class
[System.Data]System.Data.Sql Client.SqlComma nd,
class [Delta]Delta.Dictionar yDispatch,
string)
IL_0014: nop
IL_0015: ldloc.0
IL_0016: stloc.1
IL_0017: br.s IL_0019
IL_0019: ldloc.1
IL_001a: ret
} // end of method Formatter::Form at1
//*************** *************** *************** *************** **
Which throws an "InvalidProgram Exception" when I try to call it. Can
anybody help me here? I'm starting to lose sleep over this.
"allfyre" <al*****@hotmai l.comwrote:
Ok, to make a long story short, I'm Emitting some MSIL from a c#
application. I know that THIS is the MSIL I want to be emitting:
.locals init ([0] class [System.Data]System.Data.Sql Client.SqlComma nd
rtn,
[1] class [System.Data]System.Data.Sql Client.SqlComma nd
CS$1$0000)
There are two locals in this method.
But THIS is the closest I can get using Reflection.Emit :
.locals init (class [System.Data]System.Data.Sql Client.SqlComma nd
V_0)
There is only one local in this method.
IL_0015: ldloc.0
IL_0016: stloc.1
And here you assign to a second local, which isn't defined. Is there an
appropriate LocalBuilder for it?
It's hard to say more without more information - I'm afraid you'd have
to try and reduce your code to a complete, compiling sample, showing the
Reflection.Emit calls you're using.
-- Barry
-- http://barrkel.blogspot.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nigel Sampson |
last post by:
ey all,
I'm in the process of creating a method of
tracking whenever an objects properties are changed. Since
its not possible to alter
existing types I decided to used a proxy generated using
Reflection.Emit which inherits from the object needed
Person p = (Person)ProxyBuilder.Construct(typeof(Person));
|
by: samlee |
last post by:
Hi All,
I'm learning how to write C# using reflection, but don't know how to
code using reflection
this.Controls.Add(this.label1);
Could anyone help, Thank in advance.
xxx======================================================================
|
by: john |
last post by:
Is there a way to use the Reflection.Emit namespace
classes to load an existing assembly, then modify it by
emitting IL to the loaded assembly, then saving the
modified assembly back to a file?
Thanks,
John
|
by: John Arthur |
last post by:
Hi,
I am reading about Reflection.Emit and I can't really imagine a real
situation where I can use this. Can someone give me an example that
can't be done without Reflection or an example of something that If
done with Reflection.Emit will be a lot faster or something sensible.
I will really appreciate your help.
Thanks :
John Arthur
|
by: Olivier BESSON |
last post by:
Hello,
I have a web service of my own on a server (vb.net). I must declare it with
SoapRpcMethod to be used with JAVA.
This is a simple exemple method of my vb source :
>************************************************************************
> <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _
> Public Function HelloWorld() As
> <System.Xml.Serialization.SoapElementAttribute("return")> String
| |
by: Luis Arvayo |
last post by:
Hi,
In c#, I need to dynamically create types at runtime that will consist of
the following:
- inherits from a given interface
- will have a constructor with an int argument
|
by: Kofi |
last post by:
Hi Everyone,
Anyone know of any developer articles, case studies, open source
programs or such the like that demonstrate ETL (Extract, Transform &
Load), by using C# and the Reflection namespace to Emit MSIL on the fly
for XML files to be loaded into a database?
I have inherited an application which has a module that does exactly
this and it looks like it came from a book/article/open source package
or something of the sort, and the...
|
by: Siegfried Heintze |
last post by:
The following perl program works when I run it from urxvt-X console on
cygwin-x windows
LC_CTYPE=en_US.UTF-8 urxvt-X.exe&
perl -wle "binmode STDOUT, q; print chr() for 0x410 .. 0x430;"
This little one liner prints the Russian alphabet in Cryllic. With some
slight modification it will also print a lot of other alphabets too --
including Hebrew, chinese and japanese.
|
by: =?Utf-8?B?QXJ0dXJvIE1hcnRpbmV6?= |
last post by:
I've been looking everywhere on how to call AddRange Method of a
List<myClassfield in Reflection.Emit
My code goes like this
MethodInfo method =
typeof(List<>).MakeGenericType(typeof(myClass)).GetMethod("AddRange",
BindingFlags.Instance | BindingFlags.Public, null, new Type {
typeof(IEnumerable<>).MakeGenericType(typeof(myClass)) }, null));
and then the implementation
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |