locked
Web Application not working when copied to another drive RRS feed

  • Question

  • User1663576622 posted

    I have a VS 2017 Web Application project.

    When the project is copied to my local C drive and I debug it using IIS Express, it runs fine and everything is all well. When I publish the site, it also works fine.

    However when I copy the project to a shared drive on the network, it fails to debug with an error in the webconfig which references my AccountProfile class which I have used to replace the Profile as it isn't available in Web Application projects.

    <profile inherits="AccountProfile">
       <providers>
          <clear />
          <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer" />
       </providers>
    </profile>

    Here is my AccountProfile class in the AppCode folder

    using System;
    using System.Web;
    using System.Web.Profile;
    
    public class AccountProfile : ProfileBase
    {
        static public AccountProfile CurrentUser
        {
            get
            {
                return (AccountProfile)Create(HttpContext.Current.User.Identity.Name);
            }
        }
    
        [SettingsAllowAnonymous(false)]
        public string MyStaffCode
        {
            get { return (string)base["MyStaffCode"]; }
            set { base["MyStaffCode"] = value; Save(); }
        }
        
    }
    

    The error I get is: Compiler Error Message: CS0246: The type or namespace name 'AccountProfile' could not be found (are you missing a using directive or an assembly reference?)

    Any ideas?

    Wednesday, October 14, 2020 11:50 AM

All replies

  • User-1330468790 posted

    Hi Idi_idi,

     

    Since you mentioned the AppCode folder, I suspect that the problem is that your classes are not compiled.

    If your application is a Web Application project rather than a Web Site project, the code files should not be in the App_Code folder.

      

    Reason:

    VS defaulted the name space for the class to ProjectName.App_Code. In this case Visual Studio defaulted the Build Action to Content, even though the type was .cs code. If you change the Build Action to Compile, you might get passed for VS IntelliSense however you might still get objects defined twice errors on deployment.

     

    Solution:

    Add another folder inside the project and put the file in.

     

    Hope this helps.

    Best regards,

    Sean

    Thursday, October 15, 2020 6:27 AM
  • User1663576622 posted

    Hi Sean,

    Thanks for your reply.

    However the code is not in the "App_Code" folder, it is in the "AppCode" folder. I have renamed the folder to "MyCode" and still get the same error.

    Also, the Build Action is set to "Compile" for the AccountProfile class.

    Thursday, October 15, 2020 8:55 AM
  • User753101303 posted

    Hi,

    And in which namespace is your class? In short you are now trying to publish source code rather than binaries? Could it be that the problem is that if the web.config depends on compiling source code you have an chickend or the egg problem?

    If you confirm this intent I would still try to move the code on which web.config depends in its own project and DLL.

    Thursday, October 15, 2020 9:54 AM
  • User1663576622 posted

    Currently they are not in a namespace. I have tried putting the class in a namespace and adding the namespace in the webconfig as:

    <profile inherits="NamespaceName.AccountProfile">

    but still same error. The bit that is throwing me is it works fine when copied to Local C drive. 

    Thursday, October 15, 2020 10:01 AM
  • User753101303 posted

    If taking things the other way round the expected approach is to publish your application to a network folder (the target may change but if publishing from VS on your own workstation it is expected that you will use "Publish" menu option).

    Stricky speaking it means the type is not found so I guess that your manual copy is omitting the binary file that includes this type. Or your intent is to publish the source code on the web server and have your app being compiled there? Could you clarify.

    Edit: or you want to publish from the command line? For example you could try https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/command-line-deployment

    Thursday, October 15, 2020 3:59 PM
  • User-1330468790 posted

    Hi Idi_idi,

     

    One way we could adopt to try to solve the problem is to 

    1. Clean solution in VisualStudio
    2. Close VisualStudio
    3. Delete all "bin" and "obj" Folders (from the whole solution) manually
    4. Delete .vs folder in case any per-user setting cause this problem
    5. Delete "packages" Folder manually
    6. Restart VisualStudio
    7. Rebuild all

    Also, you could check this document to see if there is a cause that is similar to your case: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0246  

      

    Best regards,

    Sean

    Friday, October 16, 2020 3:28 AM
  • User1663576622 posted

    Hi Sean. I have tried the above with no luck. I have also tried creating a brand new test project and testing and it still has the same issue. Works on my local C drive but not when moved to a network drive.

    Friday, October 16, 2020 10:36 AM
  • User753101303 posted

    As you have a AppCode folder (not App_Code though) could it be that you try to handle your "Web Application Project" as a "Web Site Project"? See for example https://docs.microsoft.com/en-us/previous-versions/aspnet/dd547590(v=vs.110) for differences (edit: and in particular regarding compilation)

    If "publish" works, let's start maybe from the beginning and explain which benefit you try to get by "moving" the site (ie you copy just source code files ?)

    Friday, October 16, 2020 11:33 AM
  • User1663576622 posted

    It was previously a web site project which I changed over to a web application project, hence why I had App_Code folder. I renamed it to AppCode (or could be anything else) to comply with the Web Application structure.

    The site is published to a Server and runs fine from there. The VS application is currently on a shared network drive. When I need to make some changes I copy the project locally to my C drive, make the change, publish to the server, and then copy the new code back to the shared drive. This works fine most of the time. However the project is quite large and takes a few minutes to copy over each time. So when making small changes, such as a small bug fix, I would like to change the code directly on the shared drive, debug and make sure it works, and then publish to server. So basically remove the step of having to copy to C drive. But it doesn't debug when running from the shared drive.

    Friday, October 16, 2020 2:36 PM
  • User-1330468790 posted

    Hi Idi_idi,

     

    What kind of access do you have on that shared drive?

    One direction that we could narrow down the problem is to check the access on the shared drive.

    Possibly the compiling process stops when the compiled file cannot be written to the shared drive.

     

    Best regards,

    Sean

    Tuesday, October 20, 2020 8:09 AM
  • User1663576622 posted

    I have full read/write access on the shared drive. 

    Wednesday, October 21, 2020 7:16 AM
  • User-1330468790 posted

    Hi Idi_idi,

     

    Sorry that we might need more information.

    1. Could you please specify how you debug on that network folder? (FTP or anything else?)
    2. Does the method you choose change the framework environment? (targeting, compiling)

     

    Just a reminder, I think you should use another source control way, for example, azure devops, or svn, which will guarantee the security and does not have those kind of problems. That's way, you don't need to copy whole project from shared drive and copy back after modification.

     

    Best regards,

    Sean

    Thursday, October 22, 2020 7:21 AM