System.Reflection Question

G

Guest

Hi all,

I m new to this class..

With System.Reflection... u can create run time objects for a specified
class in a assembly...

Now if once the Assembly is loaded in the memory then does that means that
it loads the Assembly again when we call the same function..

Here is the code to make some more sense to my question

Public Function MyFunction()
Dim MyAssembly As System.Reflection.Assembly
Dim Str As String
Str = "C:\TEMP\TempProject\WindowsApplication3\ClassLibrary1\bin\" &
"ClassLibrary1.dll"
MyAssembly = MyAssembly.LoadFrom(Str)
Dim MyType As Type = MyAssembly.GetType("ClassLibrary1.Class2")
Dim Test As Object
Test = Activator.CreateInstance(MyType)
Test.CallMyFunction("Testing")
End Function

Now if i call this function in a loop then does it means that the Assembly
is loaded again. OR once the assembly is loaded it wont be loaded again in
the memory???

And are the assembly shared at all??? and what bout if its in the Web
enviornment would it be in the IIS memory???

Plz reply

cheers
chintan
 
M

Mattias Sjögren

Now if i call this function in a loop then does it means that the Assembly
is loaded again.

No, it's only loaded once. But if you intend to call this in a loop it
would still be more efficient to move the LoadFrom and GetType calls
outside the loop.

And are the assembly shared at all???

Not sure what you mean here.



Mattias
 
G

Guest

Thanks Mattis

With this i mean.... that if the Assembly is not loaded again... Then would
it share the Information ??? Here is a example for which will make things a
bit more clear.

First Class
Assembly Code (ClassLibrary1.dll)

Public Class Class2
Public Function GetuserID()
Return USerID_VAlue
End Function

End Class

and now added a public module to it.
Public Module Module1
Public USerID_VAlue As String

Public Property UserID() As String
Get
UserID = USerID_VAlue
End Get
Set(ByVal Value As String)
USerID_VAlue = Value
End Set
End Property
End Module
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Assembly ......
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Now in our Application Assembly...


Public Function MyFunction
Dim MyAssembly As System.Reflection.Assembly
Dim Str As String
Str = "C:\TEMP\TempProject\WindowsApplication3\ClassLibrary1\bin\" &
"ClassLibrary1.dll"
MyAssembly = MyAssembly.LoadFrom(Str)
ClassLibrary1.UserID = "Chintan"
Dim MyType As Type = MyAssembly.GetType("ClassLibrary1.Class2")
Dim Test As Object
Test = Activator.CreateInstance(MyType)
MsgBox(Test.GetuserID)
End function

Now.... If i get the GetUserID function.. and its giving me Blank.... as It
was loaded again.. or what??? i m confused here... If the Assembly hasnt
loaded agian.. then why should i dont get the the old value???? and it resets
the whole the value?

So does that mean that it had created a new copy of the DLL in the memory or
all the modules in the memory???

Plz Help
Cheers
C
 

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