none
constructor without body RRS feed

  • Question

  • I am working on a project I found code similar to this and it compiles fine; Note the class declares two constructors without body.

    I also noticed that the .net library class SoapHeader declares constructor without body..

    I tried similar code on my laptop Visual studio 2013 but I get compile error: constructor must have body because it is not  declared abstract ,extern or partial.

    How come it compiles in project environment (windows server ; visual studio 2012) and not in vs 2013?

     [Serializable]
     public class AuthenSoapHeader : SoapHeader, ISerializable
     {
            public AuthenSoapHeader();
            public AuthenSoapHeader(SerializationInfo info, 
                   StreamingContext context);
    
            public string MACAddress { get; set; }
    
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                throw new NotImplementedException();
            }
        }
    

    Tuesday, April 17, 2018 12:25 AM

Answers

  • I mean that if you have a reference to SoapHeader in your code and you hover over it, right click, and hit "Go to definition", it will show you metedata from the library that contains SoapHeader, not the source code. The metadata won't contain method bodies.

    So I was asking if that is what you did, which would explain why you don't see bodies for the constructors.

    • Marked as answer by kobosh Tuesday, April 17, 2018 2:44 PM
    Tuesday, April 17, 2018 3:24 AM

All replies

  • How come it compiles in project environment (windows server ; visual studio 2012) and not in vs 2013?

    Maybe, because you are using different .NET Frameworks between the different environment?

    Tuesday, April 17, 2018 12:48 AM
  • Are you sure the code that you are looking at that works is real code? Or is it actually just metadata from a "go to definition"?

    Tuesday, April 17, 2018 1:09 AM
  • the same .net 4
    Tuesday, April 17, 2018 3:08 AM
  • the same .net 4
    Tuesday, April 17, 2018 3:09 AM
  • i dont understand what you mean; soapheader is known .net library class ;
    Tuesday, April 17, 2018 3:11 AM
  • I mean that if you have a reference to SoapHeader in your code and you hover over it, right click, and hit "Go to definition", it will show you metedata from the library that contains SoapHeader, not the source code. The metadata won't contain method bodies.

    So I was asking if that is what you did, which would explain why you don't see bodies for the constructors.

    • Marked as answer by kobosh Tuesday, April 17, 2018 2:44 PM
    Tuesday, April 17, 2018 3:24 AM
  • yes you are right I did go to definition.....
    Tuesday, April 17, 2018 2:44 PM