How do I call a dll-class (compiled in C#) from ASP.NET

HiThere
HiThere used Ask the Experts™
on
I have compiled my dll in C# (MyDLL.dll). Now I want to use it from within a ASP.NET page (Deafult.aspx) but I dont seem to be able to import its namespace (MyNamespace) or any reference to it.

I have tried <%@ import namespace=MyNamespace%> and even <%@ import namespace=MyDLL%>. I have also tried to reference the dll from a separate class which I called using <%@ language=C# src=Default.aspx.cs inherits=MyClass>, which returned the same error (could not find namespace MyNamespace (or MyDLL resepctively))

I am not using Visual .NET and can terefore not create a ASP.NET project with the wizard. I need to know where to put the refence to my dll manually.

Any ideas ?

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I've never done it without the IDE but maybe this will help.  With the IDE, I created a DLL and also an EXE that referenced the DLL.  (The DLL was written in VB.NET and the client project is an EXE, unlike your situation, but I doubt that matters).  Here's what the client project's .proj files contained:

<VisualStudioProject>
    <VisualBasic
        ProjectType = "Local"
        ProductVersion = "7.0.9466"
        SchemaVersion = "1.0"
        ProjectGuid = "{C916D67B-1DFE-49A9-B4E9-DE04DA071523}"
    >
        <Build>
            <Settings
                ApplicationIcon = ""
                AssemblyKeyContainerName = ""
                AssemblyName = "TestDriver"
                AssemblyOriginatorKeyFile = ""
                AssemblyOriginatorKeyMode = "None"
                DefaultClientScript = "JScript"
                DefaultHTMLPageLayout = "Grid"
                DefaultTargetSchema = "IE50"
                DelaySign = "false"
                OutputType = "WinExe"
                OptionCompare = "Binary"
                OptionExplicit = "On"
                OptionStrict = "Off"
                RootNamespace = "TestDriver"
                StartupObject = "TestDriver.Form1"
            >
                  ... a bunch of <Config> tags...

            </Settings>

            <References>

                  ... a bunch of <Reference> tags...

                <Reference
                    Name = "MyDll"
                    AssemblyName = "MyDll"
                    HintPath = "..\MyDll\bin\MyDll.dll"
                />
            </References>
            <Imports>

                  ... and so on ...

Can you simply add the <Reference ... /> tag to your .proj file (in my case, it was a .vbproj file)?

Author

Commented:
Hi mcsilver,

Thanks for the explanation. I have no doub that your suggestion works if you habve Visual VB.NET on your computer.

My problem is that I dont have Visual VB.NET, and my development software does not feature "*.*proj*" files in the case of aspx. I am trying to reference my dll from a "stand-alone" .aspx, which is not part of any project.

I am cuurenlty using "Sharp Develop" which is a free .Net devlopment environment that does not support ASP.NET projects (only Windows Form projects). So I have no wizards that do the job for me. I wondered if there is a way to reference .NET compiled dll files manually in an aspx (without the automation of a development environment such as Visual VB.NET).

To re-phrase my question: I want to know how to reference a dll, that was compiled in .NET (in my case C#) in an aspx page. Previously (with COM and ASP), we used Server.CreateObject(MyDll.MyClass). This does not seem to work in .NET with C# compiled libraries.

Author

Commented:
Hi mcsilver,

I checked again and found the mistake: I did not put my .dll into the "bin" directory. But your comment about the <register> block pointed my into the right direction.

Thanks.

Commented:
Excellent :)

So given that you don't have a project file to work with, what was your final solution?

Author

Commented:
I put the .dll into the "bin" directory and used <%@Page runat=server codebehind=MyDll.aspx.cs inherits=MyDll.MyClass%> at the top of my .aspx. Then I use the Page_OnLoad event from within MyClass to populate listboxes on the aspx page.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial