We have encountered some weird things while reflecting generic delays. In some cases with an etched debugger, we can make impossible calls, whereas without the debugger we can not get any exceptions and applications fast.
Here is the code:
using the system; Using System.Windows.Forms; Using the system. Namespace Generic Delegate {Public Partial Category Form 1: Form {Public Form 1 () {Initialize Companent (); } Personal Representative Class 2 Representative 1 (); Private Zero Button 1_Click (Object Sender, EventArgs E) {MethodInfo mi = typeof (class 1 ) GetMethod ("GetClass", BindingFlags.NonPublic | BindingFlags.Static); If (miles! = Null) {Delegate1 del = (Delegate1) representative Crediget (typef (delaygate 1), mi); MessageBox.Show ("1"); Try {del (); } Catch (exception) {message box. Show ("No, I Can not Hold It"); } MessageBox.Show ("2"); Mi.Invoke (empty, new object [] {}); // It's OK, we'll get an exception here MessageBox.Show ("3"); }} Classroom class 2 {} square class 1 & lt; T & gt; : Class 2 {Internal Stable Class 2 Guest Class (Type} = Typef (T); MessageBox.Show ("type name" + type. Full name + "type:" + type + "assembly" + type. Assembly); Return new class 1 & lt; T & gt; ();
There are two problems:
- with the behavioral debugger and without
- without the debugger can not catch this error with the CLR move It's not just CLR exception, reading zero pointer inside the internal code, there is Memory Access Sheeting.
Use the case: You can develop something like plugins system for your app. You read an external assembly, find the appropriate method in some ways, and execute it. And we just forgot that we have to check whether it is normal or not. Under VS (and 2.0 to 4.0) everything works fine Called function does not use static references of normal type and type parameters. But there is no sound without the VS app.
Tested with .NET 4.0
The question is: why VS gets caught but not runtime?
OK, yes, that does not behave very beautifully. NET 4.0 is fixed, then the CreateDelegate () method taps. Although the JIT adapter is still not graceful when it is enabled, it believes that the CreateDelegate can not return empty and does not check the tap. You will get a fatal executionengine error instead of NRE, which is no longer captable in exception 4.0
I recommend that you report the blame for connecting. Microsoft.com Not so sure they will take you seriously, I do not know what their policy is when you deliberately bypass security measures. It may well be that they consider FEE to be very good. The workaround is clear, only call concrete type methods.
Comments
Post a Comment