Dani
Dani

Reputation: 2550

why does this kill vs 2010

If you copy this into VS2010 it sobs and dies. Why?

A colleague sent this to me in a mail saying that this is why the dynamic keyword is dangerous and warning that it'd kill VS, I copied it into what I was working on and lo and behold, VS2010 crashed.(Destroying most of what I'd worked on that morning).

Warning , it'll kill VS without compiling or any other input, if it's there VS will crash.

namespace Crash
{

    public class Foo
    {
        public static void Method(object o)
        {

        }
    }

    public class Bar
    {
        public Foo Foo { get; set; }

        public static void Method(dynamic d)
        {
            Foo.Method(d); //This crashes VS instantly!
        }
    }
}

Upvotes: 2

Views: 148

Answers (1)

OKEEngine
OKEEngine

Reputation: 908

Someone has already logged a bug for this.

http://connect.microsoft.com/VisualStudio/feedback/details/704397/vs-crash-when-passing-dynamic-val-to-static-member-of-class-from-a-static-method-in-c

Conditions necessary to cause the crash:

  • The static method being called must be referenced via only the class name (i.e. without a namespace).
  • The method making the call must also be static, and the class it belongs to must have a non-static property with the same name as the class whose method is being called.
  • The dynamic value being passed to it can come from anywhere - it doesn't have to be an argument to the calling function as in the example.

Upvotes: 8

Related Questions