PC Review


Reply
Thread Tools Rate Thread

"Assembly.Load()" - How to find an assembly using an alternate path

 
 
JohnE
Guest
Posts: n/a
 
      13th Apr 2008
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
App fails to load resource assembly with "Setup failed with hr =0x80070005" Achim Domma Microsoft ASP .NET 0 21st Aug 2006 07:36 PM
At wits end dealing with "Assembly's manifest does not match assembly reference". Need help understanding the process. Richard Lewis Haggard Microsoft C# .NET 3 26th Feb 2006 01:14 AM
Load Assembly Type.GetType("Class,Assembly") Mohamed Zaki Microsoft Dot NET Framework 4 7th Jan 2006 06:32 PM
Assembly loading error "manifest definition... does not match assembly reference" Gary McGill Microsoft Dot NET 3 24th May 2005 01:58 PM
How to use Assembly.LoadFile to load assembly in different path? =?Utf-8?B?bGVlenE=?= Microsoft Dot NET Framework 0 19th Jun 2004 07:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:13 PM.