Hi there,
Given an assembly qualified name such as the following:
"TestApp.MyBaseClass, TestLib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a537b2d901ec5912"
I need to retrieve the "System.Type" for this at runtime given only the
string itself (which I don't know ahead of time). I'd like the search for
the assembly to follow the standard .NET probing rules but if this fails
then I want to search a specific folder which my users will customize (using
my app's settings). After some research it appears that the most appropriate
way to do this is to strip the type name off ("TestApp.MyBaseClass") and
then pass this to "Assembly.GetType(string name)". However, in order to
create the latter "Assembly" object itself, I need to construct an
"AssemblyName" object from the assembly name portion of the above string
("TestLib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a537b2d901ec5912"), set its "CodeBase" property to my user's
custom folder, and then pass this to "Assembly.Load(AssemblyName
assemblyRef)". The issue I have is this:
As I understand the docs, or rather what a MSFT blogger seemed to imply on
the subject (while tyring to clarify the issue), you can set the
"AssemblyName.CodeBase" property to just a path only so that if the standard
probing rules fail then "Assembly.Load(AssemblyName assemblyRef)" should
look for the "AssemblyName" in the "CodeBase" path instead (which can be
anywhere in my case - it's not necessarily in my app's folder). Testing
shows this doesn't work however. Apparently "CodeBase" has to contain a file
name and not just a path. I would therefore have to set it to "TestLib.dll"
using the above example but this begs the question, how do I know what
extension to use (".dll" in this case") since an assembly qualified name
contains a "simple" name only (no extension). I can't even find any
documentation that explains how .NET itself determines what extensions it
tries when following the usual probing rules. Can anyone shed any light the
subject (how do I pull this off). Thanks.
|