locked
Class View - Namespace apperaing in two places RRS feed

  • Question

  • User438705957 posted

    I built a web api controller that handles file operations requested by the client.
    I initially created two classes in the same file under the namespace GNC_Corp.FileUpload.  (GNC_Corp is the project name and root namespace)
    The two classes were FileUploadController and FileOperations.

    I then decided to extract the FileOperations class into a separate file under the App_Code directory.
    This all compiled successfully ( I had to set the 'Build Action' to 'compile' for it to recognise the FileOperations class.

    When I go into Class View, it now shows GNC_Corp in two separate sections, each with a FileUpload namespace and a FileOperations class.
    One of them also has the FileUploadController class.

    I do not understand why I have two GNC_Corp sections, each with a FileUpload namespace and a FileOperations class.





    Friday, October 7, 2016 1:23 AM

Answers

  • User-2057865890 posted

    Hi Madog,

    App_Code folder is a special ASP.NET RUNTIME folder. Any files in this folder are compiled by ASP.NET when your site is actually running on the server. ASP.NET is trying to compile your App_Code folder (as it is a special Runtime folder and that is an expected behavior) which will result in duplicate declaration of your class (one in the referenced project DLL and second in the dynamic compilation). As you can imagine duplicate declaration of same type is not desirable.

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 2:48 PM

All replies

  • User-2057865890 posted

    Hi Madog,

    App_Code folder is a special ASP.NET RUNTIME folder. Any files in this folder are compiled by ASP.NET when your site is actually running on the server. ASP.NET is trying to compile your App_Code folder (as it is a special Runtime folder and that is an expected behavior) which will result in duplicate declaration of your class (one in the referenced project DLL and second in the dynamic compilation). As you can imagine duplicate declaration of same type is not desirable.

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 2:48 PM
  • User438705957 posted
    Thanks Chris,
    No, it doesn't make sense to have two declarations, but I understand your explanation.
    Wednesday, October 12, 2016 7:17 AM