Client - server aplikacija. Komunikacija je urađena preko WCF-a
Client aplikacija je jedan exe fajl cija je jedina uloga da preuzme fajlove (pluginove) sa servera i da ih pokrene. Pri startovanju programa client proveri koje fajlove treba da ima i ako mu neki nedostaje zatraži od servera da mu pošalje fajl ..... i sve to lepo radi ... fajlovi se prebace i svi srećni i zadovoljni do sad.
Da kažemo da client dobije 3 fajla i to:
1. interfaces.dll
2. common.dll
3. orders.dll - ovaj fajl ima reference ka oba gore pomenuta fajla
Kad se fajlovi snime na client-u kreće njihovo učitavanje sa sledećim kodom
Code:
Dim dir As New IO.DirectoryInfo(My.Application.Info.DirectoryPath)
For Each fi As FileInfo In dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly)
Try
Dim ass As Assembly
ass = Assembly.LoadFile(fi.FullName)
If Not ass Is Nothing Then
For Each ty As Type In ass.GetTypes
If Not ty.GetInterface(GetType(IClientPlugIn).FullName) Is Nothing Then
_MainPlugins.Add(DirectCast(ass.CreateInstance(ty.FullName), IClientPlugIn))
End If
Next
End If
Catch ex As Reflection.ReflectionTypeLoadException
'todo: log greške
Throw ex
End Try
Next
Dim dir As New IO.DirectoryInfo(My.Application.Info.DirectoryPath)
For Each fi As FileInfo In dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly)
Try
Dim ass As Assembly
ass = Assembly.LoadFile(fi.FullName)
If Not ass Is Nothing Then
For Each ty As Type In ass.GetTypes
If Not ty.GetInterface(GetType(IClientPlugIn).FullName) Is Nothing Then
_MainPlugins.Add(DirectCast(ass.CreateInstance(ty.FullName), IClientPlugIn))
End If
Next
End If
Catch ex As Reflection.ReflectionTypeLoadException
'todo: log greške
Throw ex
End Try
Next
Valjda je jasno šta kod radi, ali ukratko client proverava sve dll-ove koji se nalaze u njegovom folderu (tu se nalaze i pomenuta tri fajla), u svim dll-ovima nalazi klase koje podržavaju IClientPlugIn i sve nađene klase dodaje u listu.
A sad problem
Code:
For Each fi As FileInfo In dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly)
For Each fi As FileInfo In dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly)
nalazi dll-ove u sledećem redosledu:
1. common.dll
2. interfaces.dll
3. orders.dll
Prilikom učitavanja prvog i drugog fajla u prolaska kroz celu petlju nema nikakvog problema, ali kad dođe do orders.dll program puca u liniji
Code:
For Each ty As Type In ass.GetTypes
For Each ty As Type In ass.GetTypes
sa greškom
Citat:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
tj. u loaderexception-u piše
Citat:
{"Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b4bfc8a83602933' or one of its dependencies. The system cannot find the file specified.":"Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b4bfc8a83602933"}
Možda i ovo ne bi bilo toliko čudan problem da nije sledećeg.
Ukoliko ugasim client-a i ponovo ga startujem onda sve radi kako treba. Jedina razlika između ova dva puta je to što su drugi put fajlovi već tu tj. ni jedan fajl se ne traži od server-a.
Rešenje problema je?
Naučio sam...
Da je važnije biti ljubazan nego biti u pravu
Da je važnije biti ljubazan nego biti u pravu