Random Developer
Random Developer

Reputation: 1344

auto-generated Code

I am working on debugging some code and noticed a bunch of auto generated methods and objects.

At the top of the code for these I find the following comment:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

How do you figure out what generated the code? My curiosity has gotten the better of me on this so that is why I ask. I have looked for parts of the comment in Google and found nothing concrete.

Upvotes: 13

Views: 41723

Answers (9)

sdaigle
sdaigle

Reputation: 121

The SVCUTIL tool from Microsoft (http://msdn.microsoft.com/en-us/library/aa347733.aspx) will generate source code files with this comment at the top of each file without identifying itself as the tool that generated the file.

Upvotes: 0

dlsou
dlsou

Reputation: 665

This is the exact comment that is generated by System.CodeDom when generating a file from an entire code compile unit.

Upvotes: -1

Ferdeen
Ferdeen

Reputation: 21822

    //------------------------------------------------------------------------------ 
    // <auto-generated> 
    // This code was generated by a tool. 
    // Runtime Version:2.0.50727.42 
    // 
    // Changes to this file may cause incorrect behavior and will be lost if 
    // the code is regenerated. 
    // </auto-generated> 
    //------------------------------------------------------------------------------



namespace FirstWeb 
{ 
    public partial class _Default 
    { 

        /// <summary> 
        /// form1 control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.HtmlControls.HtmlForm form1; 
    } 
} 

You will not change this auto-generated C# file. As you keep adding ASP.NET controls to the page, this file grows with the additional declarations. In the older versions of C# (before version 2.0) and Visual Studio (before Version 2005), this code would be in the regular Default.aspx.cs file as well.

With the introduction of partial classes in C#, the code belonging to the same class can be split across multiple files. Here you see the “public partial class _Default’, which is used to hold the code generated by the Visual Studio designer. You will see the same class signature in the Default.aspx.cs file as well (you use this to write your own custom code).

So, the developer (you) and the designer (Visual Studio) can work independently without stepping over each other.

This is taken from First Web Program (Web Project) in C# Explained

Upvotes: 3

Rich
Rich

Reputation: 2279

These comments exactly match those found in some of my service reference files. These are generated proxy files for WCF services, so perhaps your code is also in this area.

If you can't see those files in Solution Explorer, click 'Show All Files' and they will appear as .cs files in the Service references node.

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1063884

Well, what code is it? Most of the MS tools include this header. xsd.exe does, sqlmetal (LINQ-to-SQL) does, etc. Try looking down a few lines... for example, a quick xsd test for me shows a second comment block:

// 
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
// 

But this doesn't exist in the LINQ-to-SQL code... ;-(

Upvotes: 0

Anton Gogolev
Anton Gogolev

Reputation: 115857

This can also be a .Designer.cs file generated by ResXFileCodeGenerator, which generates strongly-typed wrappers for .resx files.

Upvotes: 2

user434917
user434917

Reputation:

I think this code was generated by the Linq to SQL engine.

you can modify it if you understand how to code with Sql Enities

Upvotes: -1

Ian Varley
Ian Varley

Reputation: 9457

Looks like Visual Studio to me. Try Googling only part of the message.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503140

It will entirely depend on what the code is.

Presumably you know the class you're debugging - whether it's part of an ORM, part of a web service generated proxy etc. That's the crucial bit of information.

Upvotes: 2

Related Questions