refer to a public shared class in app_code folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Web Search Store

    refer to a public shared class in app_code folder

    Hello,

    I made a web page using visual studio.

    I also made a public class in the app_code folder called 'allvars'

    In the main web page durning the page startup, I can refer to public shared
    variables by simply saying:

    x=allvars.varia ble1

    where the allvars class looks like this:

    Public Class allvars

    Public Shared variable1 As Integer

    end class



    All seems well in development



    But when I copy it to the web site folder (copy all files in the asp.net web
    site (app_code folder too)



    But when I call it, it gives this error:



    Name 'allvars' is not declared.


    So in development, it knows where the class is, but in the real web it
    doesn't.



    How do I solve this problem? I also tried publishing it to the web folder,
    and that didn't work either.



    I don't care about performance, or precompileing, just want it to work.



    Thanks for any help!



    Scott




  • bruce barker

    #2
    Re: refer to a public shared class in app_code folder

    probably a namespace problem. when vs compiles the codebehind it passes
    default namespaces to the vb compiler (c# doesn't use this feature).
    when you let asp.net compiel your project, the namespace is not set.

    you should download the deployment project and use it. it will handle
    these issues for you, or read the documentation, so you know what to deploy.

    also I hope you know that shared variables are shared across all
    requests, so be sure to use locks so two requests do not try to change
    them at the same time.

    -- bruce (sqlwork.com)

    Web Search Store wrote:
    Hello,
    >
    I made a web page using visual studio.
    >
    I also made a public class in the app_code folder called 'allvars'
    >
    In the main web page durning the page startup, I can refer to public shared
    variables by simply saying:
    >
    x=allvars.varia ble1
    >
    where the allvars class looks like this:
    >
    Public Class allvars
    >
    Public Shared variable1 As Integer
    >
    end class
    >
    >
    >
    All seems well in development
    >
    >
    >
    But when I copy it to the web site folder (copy all files in the asp.net web
    site (app_code folder too)
    >
    >
    >
    But when I call it, it gives this error:
    >
    >
    >
    Name 'allvars' is not declared.
    >
    >
    So in development, it knows where the class is, but in the real web it
    doesn't.
    >
    >
    >
    How do I solve this problem? I also tried publishing it to the web folder,
    and that didn't work either.
    >
    >
    >
    I don't care about performance, or precompileing, just want it to work.
    >
    >
    >
    Thanks for any help!
    >
    >
    >
    Scott
    >
    >
    >
    >

    Comment

    • Web Search Store

      #3
      Re: refer to a public shared class in app_code folder

      Thank you very much. I'll check into these things.

      I don't want users to collide over the variables. I thought each time
      someone started the page, it was a whole new set of variables.

      You mean if 20 users get on, they will be all changing each other's
      variables?

      Thanks.

      Scott
      "bruce barker" <nospam@nospam. comwrote in message
      news:eL5OkrX3IH A.3500@TK2MSFTN GP05.phx.gbl...
      probably a namespace problem. when vs compiles the codebehind it passes
      default namespaces to the vb compiler (c# doesn't use this feature). when
      you let asp.net compiel your project, the namespace is not set.
      >
      you should download the deployment project and use it. it will handle
      these issues for you, or read the documentation, so you know what to
      deploy.
      >
      also I hope you know that shared variables are shared across all requests,
      so be sure to use locks so two requests do not try to change them at the
      same time.
      >
      -- bruce (sqlwork.com)
      >
      Web Search Store wrote:
      >Hello,
      >>
      >I made a web page using visual studio.
      >>
      >I also made a public class in the app_code folder called 'allvars'
      >>
      >In the main web page durning the page startup, I can refer to public
      >shared variables by simply saying:
      >>
      >x=allvars.vari able1
      >>
      >where the allvars class looks like this:
      >>
      >Public Class allvars
      >>
      >Public Shared variable1 As Integer
      >>
      >end class
      >>
      >>
      >>
      >All seems well in development
      >>
      >>
      >>
      >But when I copy it to the web site folder (copy all files in the asp.net
      >web site (app_code folder too)
      >>
      >>
      >>
      >But when I call it, it gives this error:
      >>
      >>
      >>
      >Name 'allvars' is not declared.
      >>
      >>
      >So in development, it knows where the class is, but in the real web it
      >doesn't.
      >>
      >>
      >>
      >How do I solve this problem? I also tried publishing it to the web
      >folder, and that didn't work either.
      >>
      >>
      >>
      >I don't care about performance, or precompileing, just want it to work.
      >>
      >>
      >>
      >Thanks for any help!
      >>
      >>
      >>
      >Scott
      >>
      >>
      >>

      Comment

      • Peter Bucher [MVP]

        #4
        Re: refer to a public shared class in app_code folder

        Hi Scott
        In the main web page durning the page startup, I can refer to public
        shared
        ^

        Be sure that all static / shared variables are on the application scope.
        So every value is the same for all users.

        --
        Gruss, Peter Bucher
        Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
        http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
        http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

        Comment

        • =?Utf-8?B?WmFpbnU=?=

          #5
          Re: refer to a public shared class in app_code folder

          Hi,
          I am also having the same issue.
          I have a class in App_Code folder.Everythi ng is fine during development.Whe
          I copy it to production server I get an error:

          The type or namespace name 'clsClientDetai ls' could not be found (are you
          missing a using directive or an assembly reference?)

          I tried creating App_Code folder is root and as virtual directory in the
          production web server, even that didn't help.

          Then created a seperate dll file with all these classes and gave a refernce
          to it in the existing project and now it was in Bin directory.But again the
          same issue.Why it could't locate the assembly or class.Even i wrapped it
          inside a namespace but that couldn't help either.

          Can somebody help me.

          Thanks in advance,
          Zainu



          "Peter Bucher [MVP]" wrote:
          Hi Scott
          >
          In the main web page durning the page startup, I can refer to public
          shared
          >
          ^
          >
          Be sure that all static / shared variables are on the application scope.
          So every value is the same for all users.
          >
          --
          Gruss, Peter Bucher
          Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
          http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
          http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
          >

          Comment

          • =?Utf-8?B?SW4gdGhlcmFweQ==?=

            #6
            Re: refer to a public shared class in app_code folder

            i experienced the same issue with class in the code_app or assemblies in the
            bin folder not being able to be referenced, after playing around not even a
            basic .aspx file would execute. The solution is to check and remove any
            app_offline.htm which often resides in the virtual directory.

            info:- http://dotnet.org.za/armand/archive/.../03/38757.aspx

            yep! that little file made me fill up my swear jar.


            Comment

            Working...