我在 VB.net 中做了一个简单的例子,编译它并运行它:
Public Class Application
Sub calc1()
Dim sq as Integer
'uncommenting this loop keeps it from compiling for some reason
'For i as Integer = 1 to 1000
' sq = i*i
'End For
Console.WriteLine("calculated squares")
End Sub
Public Shared Sub Main()
Dim startTime as DateTime
Dim endTime as DateTime
System.Console.WriteLine("Hello world!")
startTime = Now
calc1()
endTime = Now
Console.WriteLine(endTime.Subtract(startTime).TotalSeconds.ToString("0.0000"))
End Sub
End Class
虽然它编译得很好,但它在运行时给出了一个奇怪的错误:
Unhandled Exception: System.InvalidProgramException: Invalid IL code in ThreadTest.Application:Main (): IL_0018: ldarg.0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in ThreadTest.Application:Main (): IL_0018: ldarg.0