Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. C# Compiler bug 2

C# Compiler bug 2

Scheduled Pinned Locked Moved Clever Code
csharphelpquestion
7 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

    [Obsolete(delegate () { return null; })]
    void testfunction() {}

    This happens in 2005 Express, not sure about 2008 or non-Express.

    M P O L L 5 Replies Last reply
    0
    • L Lost User

      In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

      [Obsolete(delegate () { return null; })]
      void testfunction() {}

      This happens in 2005 Express, not sure about 2008 or non-Express.

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #2

      Confirmed under VS2005

      Bar fomos edo pariyart gedeem, agreo eo dranem abal edyero eyrem kalm kareore

      1 Reply Last reply
      0
      • L Lost User

        In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

        [Obsolete(delegate () { return null; })]
        void testfunction() {}

        This happens in 2005 Express, not sure about 2008 or non-Express.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        And that's subtle... how? :confused: P.S. And how did you fix it?

        L 1 Reply Last reply
        0
        • L Lost User

          In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

          [Obsolete(delegate () { return null; })]
          void testfunction() {}

          This happens in 2005 Express, not sure about 2008 or non-Express.

          O Offline
          O Offline
          OregonGhost
          wrote on last edited by
          #4

          Doesn't crash in Visual Studio 2008 SP1.

          1 Reply Last reply
          0
          • L Lost User

            In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

            [Obsolete(delegate () { return null; })]
            void testfunction() {}

            This happens in 2005 Express, not sure about 2008 or non-Express.

            L Offline
            L Offline
            Lutoslaw
            wrote on last edited by
            #5

            harold aptroot wrote:

            [Obsolete(delegate () { return null; })] void testfunction() {}

            Who would need something like this and how did you spot it?! Ideed, putting an anymous method as a parameter of Attributte is hard to presume for the compiler creators...

            Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

            1 Reply Last reply
            0
            • P PIEBALDconsult

              And that's subtle... how? :confused: P.S. And how did you fix it?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              PIEBALDconsult wrote:

              P.S. And how did you fix it?

              With a terrible workaround, that doesn't make me happy at all.. Instead of passing a delegate as argument I now have a static method in the attribute that lets you register one with a certain type. It's not a complete workaround however, this way a certain delegate is always bound to a certain type, for every field/property. Even name/type pairs wouldn't have to be unique, and I wouldn't like to need lots of reflection..

              1 Reply Last reply
              0
              • L Lost User

                In this case, the code that causes it is illegal - but that is no excuse for the compiler to crash with a "Report crash?" dialog! It happens when you try to use an anonymous delegate as an argument to an Attribute, and the delegate returns something. Like so:

                [Obsolete(delegate () { return null; })]
                void testfunction() {}

                This happens in 2005 Express, not sure about 2008 or non-Express.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Error 1 Expression cannot contain anonymous methods or lambda expressions
                Error 2 Cannot convert anonymous method to type 'string' because it is not a delegate type

                VS 2008 Professional SP1 here. regards

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups