Edit: { I think I've added a lot (too much) of information (reading) here. The important bits of what I want is:
}
I'm trying to include additional C# source files to my ASPX file, it is not working.
I have Default.aspx (with @ Page CodeFile="Default.aspx.cs") and would like to reference other files (e.g. LinkList.cs, SQLiteDB.cs, SQLServerDB.cs, JSON.cs).
I'm thinking it should be something like this (in the Default.aspx file):
// <%@ Reference Page="secondfile.cs" %>
I am new to ASP/.NET but have some experience with C# and am very experienced with PHP, JS, client-server model, etc. I have tried various ways to include them but to no avail; attempts listed below.
My setup uses a Web Site (compiled on demand; App vs. Site), using a text editor (NOT VS!) to edit the remote files. I started with VS but determined after hours of debugging that my server requires various different settings than my VS project and I do not want to maintain multiple versions of the same code... As such, and as I am on a deadline, even if I could get VS to work with my setup (comments welcome), my primary concern is to just get the code working with the server.
Things that do work:
Things that don't work:
actually using the following does seem to cause the files to load, but I still get an error: "CS0246: The type or namespace name 'SQLServerDB' could not be found (are you missing a using directive or an assembly reference?)"
<%@ Assembly Src="SQLServerDB.cs" %>
<%@ Assembly Src="DataSource.cs" %>
I'm not sure what else to try... please help. I've tried various combinations with other asp directives too.
Update/Clarification: What I'm asking is since I'm using a Web Site setup (NOT Web Application), how can I tell the ASP Server to compile other source code with the CodeFile? Answers so far do not address both aspects of this situation. The 'using' command doesn't tell the compiler where the code files are, just desired classes.
Here is two solutions that presently work for me. Unfortunately I tried these previously and they didn't work. I don't have access to the web server setup so I don't know why they didn't work previously.
As @Alexei Levenkov suggested, use the App_Code directory. This had not previously worked for me, and since I'm new to ASP.NET and every other language I have ever used requires somehow explicitly specifying the needed source files, this solution is foreign and I am completely not surprised that this did not make sense at first. Also, (almost) all the documentation I found referred to the App_Code directory in the context of a Web Application, and so I disregarded it as it seemed to be just a standard name and I could use whatever I wanted, not a magic name respective to .NET.
The other solution is to use the following directly under the @Page directive in the .ASPX file. Note: using a path in "App_Code" only works in whatever situation causes .NET to not register "App_Code" as a magic directory; I do not know what these situations are, I just know that they are possible and I encountered them.
<%@ Assembly Src="App_Code/Utilities/SQLServerDB.cs" %>
<%@ Assembly Src="App_Code/Utilities/Functions.cs" %>
<%@ Assembly Src="App_Code/Utilities/Database.cs" %>
<%@ Assembly Src="App_Code/Utilities/LinkedList.cs" %>
<%@ Assembly Src="App_Code/DataObjects.cs" %>
Also note: these solutions I found are namespace irrelevant. I mean, these solutions cause other source files to be linked together when compiled, and has absolutely nothing to do with the structure of the code. Any files could be in any accessible directories and could all be in the same namespace or different ones. Comments by others suggesting namespaces did not work because this was not the issue I was having. Each source file DOES need a "using" statement to reference other namespaces though; but this has nothing to do with where the source code is located.
Thanks to all those who made suggestions!