开发者

Isinst opcode returns null value when it shouldn't

recently I have overwritten sysglobl.dll in the GAC by adding IL code to one of the functions in CultureDefinition Class, so the the .net framework and visual studio load the changed dll directly from GAC. The function is:

System.Globalization.CalendarId CalendarIdofCalendar(System.Globalization.Calendar)

here is the code from ildasm tool.

IL_0077:  ldarg.0  
IL_0078:  isinst     [mscorlib]System.Globalization.KoreanCalendar  
IL_007d:  brfalse.s  IL_0081  
IL_007f:  ldc.i4.5  
IL_0080:  ret  
IL_0081:  ldarg.0  
IL_0082:  isinst开发者_运维技巧     [mscorlib]System.Globalization.HijriCalendar  
IL_0087:  brfalse.s  IL_008b  
IL_0089:  ldc.i4.6  
IL_008a:  ret  

The Added Code

    IL_008b:  ldarg.0  
IL_008c:  isinst     [mscorlib]System.Globalization.PersianCalendar  
IL_0091:  brfalse.s  IL_0096  
IL_0093:  ldc.i4.s   22  
IL_0095:  ret  

End Of Added Code

IL_0096:  ldarg.0  
IL_0097:  isinst     [mscorlib]System.Globalization.UmAlQuraCalendar  
IL_009c:  brfalse.s  IL_00a1  
IL_009e:  ldc.i4.s   23  
IL_00a0:  ret  
IL_00a1:  ldstr      "CustomCaledarsNotSupported"  
IL_00a6:  call       string   System.Globalization.CultureAndRegionInfoBuilder::GetResourceString(string)  
IL_00ab:  newobj     instance void  [mscorlib]System.NotSupportedException::.ctor(string)    
IL_00b0:  throw  

now here is the problem at line

__IL_008c: isinst [mscorlib]System.Globalization.PersianCalendar__     

when i pass an instance of PersianCalendar isinst returnS null value so the function will throw NotSupportedException. but if i pass HijriCalendar it work fine and will go to line

**IL_0089: ldc.i4.6**  

and so on.

i cannot find the reason why the part i have added wont works.

Thank you in advance.


How exactly are you making the change? The code itself looks good, my guess is that the metadata tables or other metadata info are getting confused so the [mscorlib]System.Globalization.PersianCalendar token doesn't actually refer to what it should, or that the actual assembly isn't getting called appropriately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜