Exposing the methods of a DLL in C# - c#

After someone creates a DLL in C# using the Microsoft Visual development environment, how would another programmer take that code, make a new project that includes the DLL's source and make a GUI that uses the DLL'S API?
I have already done the following four steps:
1) In the Solution Explorer right-click "References" and select "Add Reference ...".
2) Select the "Browse" tab.
3) Navigate to the DLL and select it.
4) Add the appropriate "using" directive to the top of the code.
What is next? After I declare a new object, how do I see what methods to use?

View Menu -> Object Browser
You should be able to look at the objects/methods and so on contained in the DLL and publicly exposed.

You should be able to use intellisense and the object explorer as always. Without the source that will be your best bet.

I don't have any code off the top of my head but have you investigated the Reflection library?
You should be able to figure out and run everything you need with that...

you can load the DLL via the .NET Reflector tool from red-gate and see all of the api and even how it was implemented http://www.red-gate.com/products/reflector/

Well...
Suppose your library is called MyLib.DLL
You would do:
MyLib ml = new MyLib();
ml.YourMethodsShouldAppearHere(); //If they are public of course.
;)

You can open any .NET DLL in this 3rd party tool called ".NET Reflector". This tool will allow you to view all the types/methods/properties and even decompile the code contained in the DLL.
.NET Reflector is similar to the object browser in Visual Studio, but is way more powerful.
If you haven't tried Reflector yet, I highly recommend it (it's really easy to use)!

Related

Import Custom .NET Library into Blue Prism Automate Folder

I am trying to create a custom library in C# using Visual Studio and then be able to refer to it from code-stages in BP objects. I know that the .dll has to be placed in the Automate folder for BP to see it, but what about .exe, config and all other files? Just placing the .dll only in the Automate folder doesn't seem to work for me. I did reference it under Code Options on the Initialize page and also placed a Namespace under Namespace Imports. But BP still tells me that the library is missing. Do I need to package as NuGet or some other way? I have zero experience doing this, so I am sorry if this is basic.
I was wondering if someone could point out some tutorial or information on how to do this A-Z, or maybe share their experience doing this? Thank you.
If you want to create a DLL to be used with Blue Prism, the best thing to do is to compile the code with all its references and resources into a single DLL.
I have always used Costura Fody to achieve that for usage in BP several times.

How do I compile C# code as a library instead of an executable?

I have a C# console application in Visual Studio 2010. It has a Main() method as well as a bunch of utility classes. I'd like those utility classes to be available to other solutions. From reading online it seems that I need to compile it as a Class Library (DLL). So here's what I did:
Went in Visual Studio to "Project > [ProjectName] Properties > Application" and changed "Output type" from "Console Application" to "Class Library"
Rebuilt; ProjectName.dll was created in bin/Debug.
Created a new Console Application
Solution Explorer > Add Reference > browse to ProjectName.DLL, select it.
However, neither IntelliSense nor the Object Browser could find the classes inside that DLL.
I tried recompiling several different Console Applications as Class Libraries and got the same result. I also noticed that it works if I initially create the solution as a Class Library, but not if I convert it to one later.
Any tips?
You do not need to build it as a dll. VS 2010 (and IIRC 2008) allow referencing exe assemblies. All you need is for they relevant types to be declared public - top-level classes defualt to internal if you don't add a specifier.
You can switch output type to Class library in project properties as well - then you will have an output as dll instead exe file
What I've always done (since this is what you do with C++ static libraries, which is what I normally use - though I think it has some advantages for C# too) is add the class library's project to the solution, then add a reference to it in the project (or projects) that uses it.
When you go to add a reference, the list of potential references includes items from the solution, so it should be fairly obvious what to do. You should then get intellisense for your library.
One advantage of doing things this way is that if you need to edit files in the library project, it's very straightforward because they are close to hand, and the project then gets rebuilt automatically when you compile the solution.
Make sure that the classes in your dll project are public.
At first, from the point of view of managed libraries it does not matter what kind of Output type is your managed library. I mean that you can successfully reference ConsoleApplication1.exe from ConsoleApplication2.exe project (so you have no reason to convert ConsoleApplication1.exe to ConsoleApplication1.dll).
At second, I've tried to reproduce your situation, but... without effect. My VS displays types/methods from ConsoleApplication1.dll. One reason I can suppose is that you have forgotten to set visibility modifier (public keyword) for your utility classes.

C# Class Library method summaries not showing in intellisense of vb.net project

(VS 2008)
I'm using a C# library for my VB.NET project. And the method summary/notes or what they are called do not show in intellisense. Is this supposed to be like that? Or is there something I must do to fix it? And if not, will VS 2010 be able to do this?
EDIT: Still unresolved. Now building library dll + xml file, but how to import the xml file in my vb project?
See image: http://i52.tinypic.com/25kh5xw.png
In C# library, go to the properties on the build tab, and check the checkbox for including XML documentation and specify the name and path. After that include the new library in your VB.Net project.
one reason could be resolved by importing the namespace needed
another reason could be due to faulty writing
if you send the code where the problem is we might be able to help you
If you're using source control (TFS or Github) then you need to the following:
Check in ( Push) for safe return point (base line)
Delete the references from the project.
Delete the custom dll's from the solution.
At this point the libs are marked as [removed], if you would add them again at this point, they will just be marked as [changed] again. This did not include the summaries for me.
Check in (push). dll's are now removed from source control as well.
Drag and drop the dll's (including xml) into the solution (I recommend using this method for including dll's
Add references to these dll's via Browse.
Check if you have summaries.
Check in (push).

Help understanding this C# library

Hi kind of a newbie question.
So apparently this library is popular for this sort of thing:
http://extracting.codeplex.com/
When I download that all I get is a .dll
I can't find documentation on their api, I don't know what I'm supposed to do with this .dll (I know how to load in functions from DLLs and such, but how when I don't even know whats in it?), can someone help me out.
start a new c# project. Open the add reference dialog and use the broswe tab, select the dll.
now open the object browser - you will see all the functions etc
edit: of course you can also download the source code from codeplex; always the ultimate form of documentation
There's a link on the same page pointing to the API documentation containing sample usage.
There is a link to an example on the codeplex site
http://extracting.codeplex.com/wikipage?title=Web%20Data%20Extracting%20and%20Analyzing%20Framework%20API&referringTitle=Home
They have limited documentation on the codeplex site, available here.
I would recommend checking that documentation to see if it meets your needs, and asking any addition questions in their Discussions Page.
To use the functionality of the DLL from your project, right click on your project file in the Solution Explorer and choose "Add Reference..". You will be presented with a dialog to choose the reference you want to add. To choose the DLL from this library, browse to it from the Browse tab.
Once you've added the reference, you won't notice a whole lot of difference - all adding a reference does is give you access to the classes that are defined withing that DLL (called an "Assembly" in .NET terms). Think of it like getting a new set of "built-in" classes in your project that you can now use. You'll want to find some documentation or ask for help on the site to learn how to use these classes.
if you are using visual studio, you can just include the dll into the reference folder of your project and then use the "using" keyword to include the library into your namespace ...
If this is a .NET assembly, then reflector will tell you what classes and methods are available. You can also reference the DLL from a C# project and then press "ctrl-alt-j" to bring up the object browser to see that data inside of Visual Studio.
You can download the source code from that page.
Look at the classes and namespaces. You can add a reference to the DLL to your project and add "using" with the namespace of the DLL to the top of any code files you need to use it in in order to have access to the classes.
Additionally you can look at some of the examples posted.
Load the dll into .net Reflector. This will list the contents of the dll and any code comments associated with the API.

My C# and DLL Data Woes

I'm trying to see if it is possible to pull data from a DLL. I did some research and found that you can store application resources within a DLL. What I couldn't find, was the information to tell me how to do that. There is a MS article that explains how to access resources within a satellite DLL, but I honestly don't know if that is what I'm looking for. http://msdn.microsoft.com/en-us/library/ms165653.aspx I did try some of the codes involved, but there are some "FileNotFoundExceptions" going on.
The rest of the DLL information is showing up: classes, objects, etc. I just added the DLL as a resource in my Visual Studio Project and added it with "using". I just don't know how to get at the meat of it, if it is possible.
If dlls are .net, you can use reflection.
Using System.Reflection;
....
Assembly A= Assembly.LoadFrom(YouDllFileName);
string[] STA;
STA= A.GetManifestResourceNames();
// STA contains all the resource names in the dll
...
// to extract them
Stream str= A.GetManifestResourceStream(STA[I]);
// then, you can make that stream became a file if you wish
You can also extract a .net assembly resources by using ildasm
I'm not totally sure what you might be running into based on your description, but a couple of general pointers...
If what you are trying to find is files you've added to the project you do this:
Right click on the resource in solution explorer, hit properties and set the "Build Action" to "Embedded Resource".
For strings and icons, add a .resx file to the project and insert them in there. If that's what you're doing and still running into issues, check the Build Action.
There is two types of dll.
Managed dll - dll that writen on any .net language (like csharp)
The link that you provide is working with managed dlls.
Unmanaged dll - classic c/cpp dll.
in this case you need to link between managed (your code) and unmanaged.
To find what the type of your dll, you need to add this dll as reference.
In visual studio open project, right click on references(in Solution Explorer).
Then "add reference"->browse-> add your dll.
Then at references, you can see your dll.
Right click on him, and add view in Object Browse.
If you see something like class "c" inside namespace "b", you working with managed dll.
In Object Browser you can learn a lot about your dll (maybe this is more important, than just extract resources)
At this point you can do the way that "Daniel Dolz" answer to you.
Since you say you are able to add the DLL in a using directive you can probably use the methods that the DLL exposes. If you do not have the documentation for the DLL then you may just have to try using the object browser to see what it has to offer.
assume:
using MyDll;
you should them be able to call the methods like this:
string x = MyDll.SomeType.GetValue();
is that what you were asking?

Categories

Resources