Using a ASSEMBLY

M

michael

General:
- Using C#
- Using notepad to program (NOT Visual Studio).

I have a code-behind file name 'example1.cs'. I want to use an Assembly
given to me for a project I'm working on. I have put the assembly named
'assembly1.dll' in the /bin directory.

How do I import/load etc the assembly so that I can use it in example1.cs?

Thanks in advance
 
V

Victor Garcia Aprea [MVP]

Hi michael,

You will need to specify the /r parameter to reference the assembly1.dll
when using csc.exe to compile your assembly.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 
M

michael

Victor,

What I want to do is the following:

/bin/given_assembly.dll

/example.cs
---------------------------------
Using given_assembly.dll // <---- ????????

public class ExampleClass {
GivenAssemblyClass ac = GivenAssemblyClass();
}
-----------------------------------

But of course, since the GivenAssemblyClass is in the given_assembly.dll and
not in the ExampleClass - it doesn't know what GivenAssemblyClass is. How
do I 'import' the assembly so that it can be used in 'example.cs'?

Thanks again
 
V

Victor Garcia Aprea [MVP]

There are two different steps:

1) You could add (not required) "using" statements at the top of your
example.cs file so you don't have to specify the full names when referencing
types defined in given_assembly.dll all along example.cs, ie:

using SomeNamespaceFromGivenAssembly;

ATypeFromGivenNamespace a = new ATypeFromGivenNamespace();

the using just saved you from having to do:

SomeNamespaceFromGivenAssembly.ATypeFromGivenNamespace a = new
SomeNamespaceFromGivenAssembly.ATypeFromGivenNamespace ();

Now for this to compile you will need to specify the /r parameter to csc.exe
so the compiler can resolve type references, ie:

csc.exe YourApp.cs /r:GivenAssembly.dll

With /r the compiler will be able to find
SomeNamespaceFromGivenAssembly.ATypeFromGivenNamespace in givenassembly.dll
and will compile your code ok.

Is this clear now? If the problem is you don't know exactly what namespaces
and types GivenAssembly offers you, then you could use a tool like Reflector
to inspect it,


--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top