J
John Lafrowda
Dear all,
here is a simple problem that I cannot overcome:
I'm trying to write a client/server application in Visual Basic .net. The
server is an executable (.exe) project, the clients are class library (.dll)
projects. The server loads the clients from their DLL-files at runtime using
reflection tools, such as:
ClientAssembly =
System.Reflection.Assembly.LoadFrom(Client_To_Load_File_Name)
In the next step, the server wants to get access to a class that is
integrated in every client. To integrate it, the class is shared by all
clients and the server on a source file basis, i.e. all clients and the
server link (not copy) to the source file. Furthermore, the root namespace
of all projects is set to "". If we call the common class "MyClass", the
server is able to gain access to a client's imported copy by calling
dim x as Object
x = ClientAssembly.CreateInstance("MyClass")
So far, this all works fine. Now, the server wants to finally cast the
resulting object to a "MyClass" object, as it knows this class by source
code:
dim y as MyClass
y = CType(x, MyClass)
The latter function, however, failes during runtime with a message that
there is no appropriate conversion between the types "MyClass" and
"MyClass".
Obviously (...I think...), the problem is related to the fact, that at
runtime both server and client have integrated their copy of the MyClass
source code into their assembly in binary format. Consequently, the .net
framework sees both versions as different types and does not find an
appropriate cast.
To get over the problem, I found only to unsatisfying solutions:
1. Compile the class definitions in another Class Library. Link server and
clients to the assembly of this class library instead of the source code. In
this case, all players access the same _binary_ representation of the class.
The problem with this solution is that I have to recompile this new, central
class library with every change.
2. I do not use the cast mechanisms but only work with objects of type
"Object". This works but source code appears to be less clear.
Now the question: Is there any method to share a file of source code that
contains structure/class definitions and is it somehow possible for an
assembly to access structure/class objects of other assemblies at runtime if
there is no reference given to these assemblies at compile time?
Thanks,
John
here is a simple problem that I cannot overcome:
I'm trying to write a client/server application in Visual Basic .net. The
server is an executable (.exe) project, the clients are class library (.dll)
projects. The server loads the clients from their DLL-files at runtime using
reflection tools, such as:
ClientAssembly =
System.Reflection.Assembly.LoadFrom(Client_To_Load_File_Name)
In the next step, the server wants to get access to a class that is
integrated in every client. To integrate it, the class is shared by all
clients and the server on a source file basis, i.e. all clients and the
server link (not copy) to the source file. Furthermore, the root namespace
of all projects is set to "". If we call the common class "MyClass", the
server is able to gain access to a client's imported copy by calling
dim x as Object
x = ClientAssembly.CreateInstance("MyClass")
So far, this all works fine. Now, the server wants to finally cast the
resulting object to a "MyClass" object, as it knows this class by source
code:
dim y as MyClass
y = CType(x, MyClass)
The latter function, however, failes during runtime with a message that
there is no appropriate conversion between the types "MyClass" and
"MyClass".
Obviously (...I think...), the problem is related to the fact, that at
runtime both server and client have integrated their copy of the MyClass
source code into their assembly in binary format. Consequently, the .net
framework sees both versions as different types and does not find an
appropriate cast.
To get over the problem, I found only to unsatisfying solutions:
1. Compile the class definitions in another Class Library. Link server and
clients to the assembly of this class library instead of the source code. In
this case, all players access the same _binary_ representation of the class.
The problem with this solution is that I have to recompile this new, central
class library with every change.
2. I do not use the cast mechanisms but only work with objects of type
"Object". This works but source code appears to be less clear.
Now the question: Is there any method to share a file of source code that
contains structure/class definitions and is it somehow possible for an
assembly to access structure/class objects of other assemblies at runtime if
there is no reference given to these assemblies at compile time?
Thanks,
John