refer to a public shared class in app_code folder

Discussion in 'ASP .Net Web Controls' started by Web Search Store, Jul 3, 2008.

  1. 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.variable1

    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
     
    Web Search Store, Jul 3, 2008
    #1
    1. Advertising

  2. Web Search Store

    bruce barker Guest

    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.variable1
    >
    > 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, Jul 4, 2008
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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.variable1
    >>
    >> 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
    >>
    >>
    >>
     
    Web Search Store, Jul 4, 2008
    #3
  4. 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
     
    Peter Bucher [MVP], Jul 7, 2008
    #4
  5. Web Search Store

    Zainu Guest

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

    The type or namespace name 'clsClientDetails' 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
    >
     
    Zainu, Jul 24, 2008
    #5
  6. Web Search Store

    In therapy Guest

    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/2005/07/03/38757.aspx

    yep! that little file made me fill up my swear jar.
     
    In therapy, Aug 23, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,419
    smith
    Dec 8, 2004
  2. DJ Dev
    Replies:
    3
    Views:
    16,205
    Gandalf
    Feb 8, 2004
  3. Howard

    shared app_code folder

    Howard, Jun 6, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    828
    Juan T. Llibre
    Jun 6, 2006
  4. Web Search Store

    refer to a public shared class in app_code folder

    Web Search Store, Jul 3, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    859
    In therapy
    Aug 23, 2008
  5. Web Search Store

    refer to a public shared class in app_code folder

    Web Search Store, Jul 3, 2008, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    205
    In therapy
    Aug 23, 2008
Loading...

Share This Page