Find a class in a solution with mulitpile projects

O

Ohad weiss

Hi all,

I have a class in project A.
At the same solution, I have another project - named project B.

I want to write a piece of code in that class from project B that finds the
class in project A. How can I do that?

I have a code to do that, if the class is in the same project (by using
Application.ProductName, but even if I chaned it to the second project name,
its didn't work), and I've referenced it because I have some froms that I
inherited from project A..
:


Code:
Function GetFormByName(ByVal stFileName As String) As Form
Dim tFormType As Type = Type.GetType(stFileName, False)
If tFormType Is Nothing Then
Dim Fullname As String = Application.ProductName & "." &
stFileName
tFormType = Type.GetType(Fullname, False, True)
If tFormType Is Nothing Then
Throw New Exception(stFileName + " could not be found")
End If
End If
Return CType(Activator.CreateInstance(tFormType), Form)
End Function

Thanks
 
C

Cor Ligthert[MVP]

Ohad

Simple use one the reference box which you can find in the Solution explorer
at top of a project of in the Project menu.

You can directly point to the other project in your solution, or to the DLL
that it has created.
Be aware that you have to in the Build options which projects and in what
other they have to be build.

As well, don't forget to set the Import directive to your namespace.
Otherwise you have to set that everytime in your code.

Cor
 
O

Ohad weiss

Thanks for the reply Cor,
But the project I'm trying to find its class (Project A) is of type Exe and
not Dll.
Therefore, I can't add a reference to it.

Ohad
 
O

Ohad weiss

Because its another exe project.
I'll try to explain:
I have a project that its results is dll. It contains that main app form(mdi
paren), login form, and general form. This project result a dll file.
In the same solution I have another 2 projects that their result is exe file
(each on of them). tese two projects has classes that inherit from the
general form in the project that created the dll.
In one of my classes in the exe projects, I need to scan a class in the
second exe project and retrieve the controls on it. This is why I cant use
it as a dll.

Is there any way to set reference to an exe project?

If I change the second param in the function tFormType =
Type.GetType(Fullname, False, True) to true, I get an exception about the
assembly:
Could not load type X from assembly Y, version=1.0...., culture=neutral,
publickeytoken=null.
X- the path and the fulename I'm trying to retrive (which is in project X)
Y - the name of project Y from which I'm trying to call the form in the
second project


Is there any way to set reference to an exe project? Or maybe you can
explain me how to set another assembly to the project

I can send the code if needed.

Thanks Ohad
 

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