AlwaysSomethingToLearn
asked on
Dynamic assembly load
I use the system.reflection namespace from a VB2005 program to dynamically load forms from unreferenced assemblies. Code below:
Dim asmFormAssembly As System.Reflection.Assembly = System.Reflection.Assembly .LoadFrom( AssemblyNa me)
Dim typToLoad As Type = asmFormAssembly.GetType(Fo rmName)
Dim objGeneric As Object = Activator.CreateInstance(t ypToLoad)
Dim frmToLoad As Form = CType(objGeneric, Form)
Return frmToLoad
If the assembly name is something like "C:\folder\folder\MyApp.ex e" and the form is "MyApp.frmDemo" everything works fine. However, if I set up a shared drive on a server (win2008), copy the assembly there and send assembly name "\\servername\sharename\My App.exe" I get the famous "object not set ot an instance of an object" error because typToLoad is returned as nothing in the above code.
The shared drive has full permissions for everone and is a simple share. It is not running under IIS so trust issues should not be an issue. The shared folder is accessible from the calling client and I can paste to it and delete from it from the client (XPpro SP3). Also, I can execute the exe assembly directly on the server.
Any ideas?
Dim asmFormAssembly As System.Reflection.Assembly
Dim typToLoad As Type = asmFormAssembly.GetType(Fo
Dim objGeneric As Object = Activator.CreateInstance(t
Dim frmToLoad As Form = CType(objGeneric, Form)
Return frmToLoad
If the assembly name is something like "C:\folder\folder\MyApp.ex
The shared drive has full permissions for everone and is a simple share. It is not running under IIS so trust issues should not be an issue. The shared folder is accessible from the calling client and I can paste to it and delete from it from the client (XPpro SP3). Also, I can execute the exe assembly directly on the server.
Any ideas?
ASKER
Gave that a try to no effect. I used CasPol for the 2.0 framework as that is what the assembly is built for. I ran CasPol on the server, do I need to run it on the client as well?
I ran CasPol on the server, do I need to run it on the client as well?No need to run it on the server. You should run it on the client and grant the network location.
ASKER
Thanks for your help, that does it. One last question before closing - am I right in assuming that if the assembly was deployed to the GAC then any trust issues go away?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for your timely responses
Network shares get Local Intranet trust levels. This is a .NET setting independent of the sharing rights and NTFS security. Try using CasPol to fully trust the assembly on the network share then try your dynamic code again.
http://msdn.microsoft.com/en-us/library/zdc263t0(v=vs.80).aspx