Need help including a class file...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wickedHangover
    New Member
    • Mar 2007
    • 11

    Need help including a class file...

    Ok, so I have my default.aspx page and with it all the contents that it needs for the default.aspx.cs page. What i want to do is seperate parts of the .CS file into a class I would call ServerConnect which will handle all my database setup calls. So I put ServerConnect.c s into the app_code directory. When I run this on my machine locally, it picks up the class file no problem but when I put the machine on a live server I get an error

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

    I'm a little bit lost, I've read in numerous places that just adding the .cs file to the app_code directory is all you need to do. I must be missing something, can anyone help me understand how to bring in additional class files into a program?

    Or am I just going about this all wrong. My intent is to create several class files that can be called by various programs without duplicating the code all the time. I just think my misunderstandin g is that I'm new to ASP, but not new to the C languages.
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    In your references you may need to add that class namespace to your project.

    Comment

    • wickedHangover
      New Member
      • Mar 2007
      • 11

      #3
      I guess I'm not really sure how to do that. My class uses a namespace so in the app_code directory I have a class class.cs and that class is of the namespace "MyClass".

      Then in the default.aspx.cs file I add the line
      using MyClass;

      Then I publish the site without any errors, line 1 of the default.aspx code correctly calls the compiled DLL by name
      <%@ page language="C#" autoeventwireup ="true" inherits="_Defa ult, App_Web_fogmnha q" %>

      but I get the error

      Could not load the assembly 'App_Web_fogmnh aq'. Make sure that it is compiled before accessing the page.

      On the server, in \bin is App_Web_fogmnha q.dll

      Is there something that is just so obvious that I am not doing in the setup? Like I said, if I run this all locally on my xp machine using the asp.net dev server it runs fine, once I publish it to a server which is running the latest asp.net 2.0 it doesn't work.

      Is there something I need to add to the web.config? Or is it somewhere else in the compiler?

      I'm just really lost on this one.

      Comment

      • wickedHangover
        New Member
        • Mar 2007
        • 11

        #4
        ok, i'm open to admit I was an idiot, actually more like IDIOT.

        The problem was not that my code was wrong, it was that IIS wasn't configured properly. Everything runs smooth as silk now.

        Comment

        Working...