all groups > dotnet clr > july 2005 >
You're in the

dotnet clr

group:

AppDomain PrivatePath under .NET 2.0 Beta 2


AppDomain PrivatePath under .NET 2.0 Beta 2 Gael Fraiteur
7/29/2005 12:00:00 AM
dotnet clr: I would like to add to the search path of my application a directory where
some plug-ins reside. But this directory is not under the application base
directory. I tried many procedures, but nothing works. By the way, these
things are quite badly documented in Beta 2.

The problem is that the runtime claims it won't take into a account a
private path that is not under the application base path. I overcame the
probleme by overloading AppDomain.AssemblyResolve, but this solution is
quite dirty.

Was someone successful with another solution?



--
Gael Fraiteur
http://gael.fraiteur.net
Prague, Czech Republic
----------------------------------------------------------------
PostSharp is an open-source post-compiler for .NET
http://gael.fraiteur.net/postsharp.aspx
----------------------------------------------------------------

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 Willy Denoyette [MVP]
7/29/2005 12:00:00 AM
Please post Beta questions to the beta forums at http://forums.microsoft.com

Willy.

[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 David Levine
7/31/2005 6:02:29 AM
Have you tried creating an app.config file that has a codebase hint to the
assembly? Also, why is subscribing to the AssemblyResolve event 'dirty'? It
sounds like it might be exactly what you need.

[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 Rick Strahl [MVP]
7/31/2005 3:59:37 PM
Hi Gael,

PrivateBinPath should work as well as ApplicationBase, but you need to be in
control of your AppDomain creation in order for that to work. Once an
AppDomain exists those properties can't be set and that might be the reason
it's not working.

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog


[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 David Levine
8/1/2005 4:16:38 AM
I am implementing a similar system and have similar problems to solve.

The current runtime 1.1 has an API called AppDomain.AppendPrivatePath that
allows you to dynamically extend the private path of the current AppDomain.
Unfortunately, this is being deprecated in Whidbey, which greatly reduces
the options available. If you are targeting the 1.1 framework then this may
provide all you need.

If you know in advance which plugins you want to load and what their private
paths are, you can create an app.config file that contains a
<configuration\runtime\assemblyBinding\probing> element that consists of the
subdirectories below the appbase you want it to automatically search. But
you already stated you need a dynamic solution.

Because the AppendPrivatePath API is obsolete you are forced to do something
such as write your own version of this that will dynamically add the paths
to a list that you use in your AssemblyResolve handler.

[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 Gael Fraiteur
8/1/2005 10:16:02 AM
Hi,

Thanks to all for your answers.
My initial problem is that I need to load plugins that eventually have
private assemblies. So I want to extend the private path of the current
AppDomain dynamically (so using app.config was not a solution). I did not
want to use AssemblyResolve because it though it was useless to implement
some logic that is already present in the framework.

Thanks again.

--
Gael Fraiteur
http://gael.fraiteur.net
Prague, Czech Republic
----------------------------------------------------------------
PostSharp is an open-source post-compiler for .NET
http://gael.fraiteur.net/postsharp.aspx
----------------------------------------------------------------

[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 Rick Strahl [MVP]
8/7/2005 9:43:31 PM

If you're adding plug-ins the best solution tends to be createing a new
AppDomain and then loading the plug-ins into that. By doing so you can get
to control the creation of hte new AppDomain and the PrivateBinPath with it.
All you have to do then is to make sure that all related assemblies exist in
the known paths that you've set up previously, which is a reasonable
requirement for add-ins.

There's no way to manipulate these settings once the AppDomain's been
created. What I have done in the past where I didn't have the choice for a
new AppDomain is go the brute force route and do my own 'shadow copying' of
assemblies from one place to another. This is ugly as sin but it worked to
make things work as long as I knew where the files where coming from.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog



[quoted text, click to view]

Re: AppDomain PrivatePath under .NET 2.0 Beta 2 Gael Fraiteur
8/8/2005 11:12:27 AM
Thank you Rick.

In my situation, I think this situation will be unusable from a performance
point of view, because I cannot afford to cross AppDomain borders for every
single call from the plug-in to the object model they are supposed to
modify. I am writing a post-compiler, so imagine that plug-ins can
potentially access the main AppDomain (where the IL DOM resides) for each IL
instruction...

I will go for the AssemblyResolve solution, i.e. I will implement a custom
binder based on this event and use the Assembly.LoadFile method.

Thank you anyway.

Gael

--
Gael Fraiteur
http://gael.fraiteur.net
Prague, Czech Republic
----------------------------------------------------------------
PostSharp is an open-source post-compiler for .NET
http://gael.fraiteur.net/postsharp.aspx
----------------------------------------------------------------

[quoted text, click to view]

AddThis Social Bookmark Button