Skip to content

Instantly share code, notes, and snippets.

@johnfn
Last active July 5, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnfn/7bfe2d8412b871ce6bc86030a47a494e to your computer and use it in GitHub Desktop.
Save johnfn/7bfe2d8412b871ce6bc86030a47a494e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace testingconsole
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(500);
Test();
}
}
static void Test()
{
Console.WriteLine("Hello World!");
var p = new Program();
Console.WriteLine(p.OtherTest());
}
// comment out this function and comment in the one below to see the error:
// Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'System.Int32'.
// at testingconsole.Program.OtherTest()
// at testingconsole.Program.Test() in /Users/johnfn/code/testingconsole/Program.cs:line 24
// at testingconsole.Program.Main(String[] args) in /Users/johnfn/code/testingconsole/Program.cs:line 15
public int OtherTest() {
return 5;
}
// public Dictionary<int, string> OtherTest() {
// return new Dictionary<int, string>();
// }
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace testingconsole
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(500);
Test();
}
}
static void Test()
{
Console.WriteLine("Hello World.");
// Console.WriteLine("Hello World 2.");
var p = new Program();
OtherTest();
}
// Comment out this function, and comment in the second "Console.WriteLine" in Test() and the function below
// to cause the bug:
public static void OtherTest() {
return;
}
// public static Dictionary<int, string> OtherTest() {
// return new Dictionary<int, string>();
// }
}
}
// Unhandled exception. IlCompilationException: System.AggregateException: Instruction compilation failed: 10: pop (Cannot Pop elements from an empty ImmutableStack)
// ---> System.InvalidOperationException: Cannot Pop elements from an empty ImmutableStack
// at LiveSharp.Runtime.Infrastructure.ImmutableStack`1.Pop()
// at LiveSharp.Runtime.IL.InstructionContext.PopStack()
// at LiveSharp.Runtime.IL.IlExpressionCompilerHandlers.Pop(InstructionContext ctx)
using System;
using System.IO;
using System.Threading;
namespace testingconsole
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(500);
Test();
}
}
static void Test()
{
// uncomment this line to see the error
// var projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent?.Parent?.FullName;
Console.WriteLine("Hello World!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment