Click here to Skip to main content
11,795,568 members (77,662 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# DLL VisualStudio2010
Hi everyone.
I have this dll named dllSource.dll, and it contains:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dllSource
    public class Operation
        public int Add(int x, int y)
            int z;
            if ((x == 10) && (y == 20))
                z = x + y;
                z = x;
            return z;

What I intend to do is to call that dll and pass parameters on it.
I want to pass 5 to x and 10 to y.
How will I so that?
Also, if I want to get the parameter type of the dll, how will I do it?

Posted 21-Mar-13 1:02am
Edited 21-Mar-13 14:32pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You will need to add your dllSource.dll to the References of your other project.
In the code for that project include a line using dllSource;
Now you can use the class in your dll like any other class or type. E.g.
private void button1_Click(object sender, EventArgs e)
    Operation o = new Operation();
    int i = o.Add(5, 10);
    // ... etc

To get the parameter type(s) and return type ...

A) Manually - Right-click on the dllSource in the References section of Solution Explorer and select "View in Object Browser"

B) Whilst typing code - using my code above as an example type o. and allow the intellisense to display then hover your mouse over the function you want the information on.

C) Programmatically - Use Reflection - have a look at this article[^]

[Edit] prompted by comment below ... you will need to declare the class and function as public for any of the above to work
toATwork at 21-Mar-13 9:16am
Manually won't work. Default visibility of class is internal.
If you have the source of the other dll ensure the class is declared public. Then you can instantiate it from other assemblies.
Member 9886727 at 21-Mar-13 21:20pm
Hi Chill60 and toAtwork,

I already updated my class in dll to public.

It seems that I am unable to create an object from it using:

object o = assembly.CreateInstance("Operation");

May I see the sample code on how to do this, please.
CHill60 at 22-Mar-13 5:19am
Are you saying that you can't add a reference to this dll into your project? Have a look at (a lot) of comments on this link if that is the case

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 340
1 Sergey Alexandrovich Kryukov 316
2 OriginalGriff 285
3 Abhinav S 223
4 KrunalRohit 214
0 OriginalGriff 1,797
1 Maciej Los 1,415
2 KrunalRohit 1,240
3 CPallini 840
4 ppolymorphe 808

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 4 Sep 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100