asp.net - How do I load a type from another assembly when in a Web App? -
i have existing code:
private function gettypefromname(byval fulltypename string, byval assemblyname string) type dim dirstr = new fileinfo(system.reflection.assembly.getexecutingassembly.location).directoryname dim asm = [assembly].loadfile(dirstr & "\" & assemblyname & ".dll") return asm.gettype(fulltypename) end function
the result of call routine type instantiated , used within app.
previous use , assumptions
this code used in winforms app locate type based on data loaded config file , passed function.
generally assembly sought referenced application, not case.
as can see, code expects assembly name passed in without ".dll" suffix or path , further assumed resident in same folder executing assembly.
these assumptions have been correct until now.
everything changes
now executing code within web app , seems folder of executing assembly is...
c:\windows\microsoft.net\framework\v2.0.50727\temporary asp.net files\<assemblyname>\ae5faeca\7d2a827f\assembly\dl3\212260f8\0af7415f_9747cc01\<assemblyname>.dll
...and further there no other dlls in folder.
i expected folder bin folder of web app , other assemblies available there.
so... how load type assembly when in web app?
what need ensure assembly trying load either lives within websites directory (bin, app_data, etc).
after need httpserverutility.mappath directory expect assembly in. once have that, you'll able load it.
private function gettypefromname(byval fulltypename string, byval assemblyname string) type dim dirstr = httpserverutility.mappath( "/bin" ) //assuming loading bin directory of website dim asm = [assembly].loadfile(dirstr & "\" & assemblyname & ".dll") return asm.gettype(fulltypename) end function
msdn httpserverutility http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
hope helps
Comments
Post a Comment