refer to a public shared class in app_code folder

  • Thread starter Thread starter Web Search Store
  • Start date Start date
W

Web Search Store

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
 
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)
 
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
 
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.
 
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
 
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.
 
Back
Top