<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx</link><description>.Net Framework has a feature called Shadow Copy . When shadow copy is enabled on an appdomain, assemblies loaded in that appdomain will be copied to a shadow copy cache directory, and will be used from there. This is great because the original file is</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#69951</link><pubDate>Tue, 10 Feb 2004 05:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:69951</guid><dc:creator>David Levine</dc:creator><description>Thanks for the info, keep it coming. On the empty string question, I'd guess that nothing would be copied since it would not locate a directory whose name was an empty string.&lt;br&gt;&lt;br&gt;A question about the shadow copy directories; you state that each directory must be specified as an absolute path. This implies that assemblies will be shadow copied regardless of their original location on the machine, or will this only affect files from subdirectories at or below the appbase? If it's from anywhere then does this mean that assemblies loaded using LoadFrom or LoadFile as opposed to Load will also be shadow copied? In other words, does the fusion load context have an effect on assemblies that are shadow copied? Thanks.&lt;br&gt;&lt;br&gt;Dave&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#70092</link><pubDate>Tue, 10 Feb 2004 13:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:70092</guid><dc:creator>Junfeng</dc:creator><description>David, &lt;br&gt;&lt;br&gt;Regarding the exercise, yes, you are correct. Nothing will be copied. &lt;br&gt;&lt;br&gt;You are correct about the LoadFrom also. Shadow copy will be applied to both Assembly.Load and Assembly.LoadFrom. What we check is that this assembly is from one of those directories. If they are, we shadow copy it. &lt;br&gt;&lt;br&gt;But Assembly.LoadFile does not benefit from shadow copy. Because LoadFile does not go throught fusion. Fusion only handles Assembly.Load(string) and Assembly.LoadFrom. </description></item><item><title>AppDomainSetup explained</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#70117</link><pubDate>Mon, 09 Feb 2004 21:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:70117</guid><dc:creator>Junfeng Zhang's .Net Framework Notes</dc:creator><description /></item><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#86041</link><pubDate>Tue, 09 Mar 2004 13:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:86041</guid><dc:creator>Junfeng Zhang</dc:creator><description>Denis sent a comment using the contact link. Please use the comment to post question. Other people may be interested in the answer. &lt;br&gt;&lt;br&gt;Shadow Copy in AppDomain is not the same as Volume Shadow Copy feature in Windows Server 2003. We don't keep track of history. It is mainly a workaround to not lock the original file.&lt;br&gt;&lt;br&gt;Sender: Denis AUGER&lt;br&gt;Email: auger_denis@emc.com&lt;br&gt;=====================================&lt;br&gt;Hi,&lt;br&gt;&lt;br&gt;I have found in the API how to active a Volume Shadow Copy with appDomain class.&lt;br&gt;&lt;br&gt;But I need, through the API, to get all the &amp;quot;previous versions&amp;quot; giving a file name.&lt;br&gt;I also need to launch a restore of a file or a directory.&lt;br&gt;&lt;br&gt;Do you know how is it possible through the API ?&lt;br&gt;&lt;br&gt;Thank's very much for your help&lt;br&gt;&lt;br&gt;Denis&lt;br&gt;</description></item><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#122956</link><pubDate>Fri, 30 Apr 2004 09:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:122956</guid><dc:creator>chornbe</dc:creator><description>You must also encapsulate the loaded assembly into another class, which is loaded by the new appdomain. Here's the code as it's working for me: (I've created a few custom exception types, and you'll notice I had them back - they're not descended from MarshalByRefObject so I can't just throw them from the encapsulated code)&lt;br&gt;&lt;br&gt;--- cut first class file&lt;br&gt;using System;&lt;br&gt;using System.Reflection;&lt;br&gt;using System.Collections;&lt;br&gt;&lt;br&gt;namespace Loader{&lt;br&gt;&lt;br&gt;	/* contains assembly loader objects, stored in a hash&lt;br&gt;	 * and keyed on the .dll file they represent. Each assembly loader&lt;br&gt;	 * object can be referenced by the original name/path and is used to&lt;br&gt;	 * load objects, returned as type Object. It is up to the calling class&lt;br&gt;	 * to cast the object to the necessary type for consumption.&lt;br&gt;	 * External interfaces are highly recommended!!&lt;br&gt;	 * */&lt;br&gt;	public class ObjectLoader : IDisposable {&lt;br&gt;&lt;br&gt;		// essentially creates a parallel-hash pair setup&lt;br&gt;		// one appDomain per loader&lt;br&gt;		protected Hashtable domains = new Hashtable();&lt;br&gt;		// one loader per assembly DLL&lt;br&gt;		protected Hashtable loaders = new Hashtable();&lt;br&gt;&lt;br&gt;		public ObjectLoader() {/*...*/}&lt;br&gt;&lt;br&gt;		public object GetObject( string dllName, string typeName, object[] constructorParms ){&lt;br&gt;			Loader.AssemblyLoader al = null;&lt;br&gt;			object o = null;&lt;br&gt;			try{&lt;br&gt;				al = (Loader.AssemblyLoader)loaders[ dllName ];&lt;br&gt;			} catch (Exception){}&lt;br&gt;			if( al == null ){&lt;br&gt;				AppDomainSetup setup = new AppDomainSetup();&lt;br&gt;				setup.ShadowCopyFiles = &amp;quot;true&amp;quot;;&lt;br&gt;				AppDomain domain = AppDomain.CreateDomain( dllName, null, setup );&lt;br&gt;				domains.Add( dllName, domain );&lt;br&gt;				object[] parms = { dllName };&lt;br&gt;				// object[] parms = null;&lt;br&gt;				BindingFlags bindings = BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public;&lt;br&gt;				try{&lt;br&gt;					al = (Loader.AssemblyLoader)domain.CreateInstanceFromAndUnwrap( &lt;br&gt;						&amp;quot;Loader.dll&amp;quot;, &amp;quot;Loader.AssemblyLoader&amp;quot;, true, bindings, null, parms, null, null, null &lt;br&gt;						);&lt;br&gt;				} catch (Exception){&lt;br&gt;					throw new AssemblyLoadFailureException();&lt;br&gt;				}&lt;br&gt;				if( al != null ){&lt;br&gt;					if( !loaders.ContainsKey( dllName ) ){&lt;br&gt;						loaders.Add( dllName, al );&lt;br&gt;					} else {&lt;br&gt;						throw new AssemblyAlreadyLoadedException();&lt;br&gt;					}&lt;br&gt;				} else {&lt;br&gt;					throw new AssemblyNotLoadedException();&lt;br&gt;				}&lt;br&gt;			}&lt;br&gt;			if( al != null ){&lt;br&gt;				o = al.GetObject( typeName, constructorParms );&lt;br&gt;				if( o != null &amp;amp;&amp;amp; o is AssemblyNotLoadedException ){&lt;br&gt;					throw new AssemblyNotLoadedException();&lt;br&gt;				}&lt;br&gt;				if( o == null || o is ObjectLoadFailureException ){&lt;br&gt;					string msg = &amp;quot;Object could not be loaded. Check that type name &amp;quot; + typeName + &lt;br&gt;						&amp;quot; and constructor parameters are correct. Ensure that type name &amp;quot; + typeName +&lt;br&gt;						&amp;quot; exists in the assembly &amp;quot; + dllName + &amp;quot;.&amp;quot;;&lt;br&gt;					throw new ObjectLoadFailureException( msg );&lt;br&gt;				}&lt;br&gt;			}&lt;br&gt;			return o;&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		public void Unload( string dllName ){&lt;br&gt;			if( domains.ContainsKey( dllName ) ){&lt;br&gt;				AppDomain domain = (AppDomain)domains[ dllName ];&lt;br&gt;				AppDomain.Unload( domain );&lt;br&gt;				domains.Remove( dllName );&lt;br&gt;			}&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		~ObjectLoader(){&lt;br&gt;			dispose( false );&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		public void Dispose(){&lt;br&gt;			dispose( true );&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		private void dispose( bool disposing ){&lt;br&gt;			if( disposing ){&lt;br&gt;				loaders.Clear();&lt;br&gt;				foreach( object o in domains.Keys ){&lt;br&gt;					string dllName = o.ToString();&lt;br&gt;					Unload( dllName );&lt;br&gt;				}&lt;br&gt;				domains.Clear();&lt;br&gt;			}&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;}&lt;br&gt;&lt;br&gt;--- end cut&lt;br&gt;&lt;br&gt;--- cut second class file&lt;br&gt;using System;&lt;br&gt;using System.Reflection;&lt;br&gt;&lt;br&gt;namespace Loader {&lt;br&gt;	// container for assembly and exposes a GetObject function &lt;br&gt;	// to create a late-bound object for casting by the consumer&lt;br&gt;	// this class is meant to be contained in a separate appDomain&lt;br&gt;	// controlled by ObjectLoader class to allow for proper encapsulation&lt;br&gt;	// which enables proper shadow-copying functionality.&lt;br&gt;	internal class AssemblyLoader : MarshalByRefObject, IDisposable {&lt;br&gt;&lt;br&gt;		#region class-level declarations&lt;br&gt;		private Assembly a = null;&lt;br&gt;		#endregion&lt;br&gt;&lt;br&gt;		#region constructors and destructors&lt;br&gt;		public AssemblyLoader( string fullPath ){&lt;br&gt;			if( a == null ){&lt;br&gt;				a = Assembly.LoadFrom( fullPath );&lt;br&gt;			}&lt;br&gt;		}&lt;br&gt;		~AssemblyLoader(){&lt;br&gt;			dispose( false );&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		public void Dispose(){&lt;br&gt;			dispose( true );&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		private void dispose( bool disposing ){&lt;br&gt;			if( disposing ){&lt;br&gt;				a = null;&lt;br&gt;				System.GC.Collect();&lt;br&gt;				System.GC.WaitForPendingFinalizers();&lt;br&gt;				System.GC.Collect( 0 );&lt;br&gt;			}&lt;br&gt;		}&lt;br&gt;		#endregion&lt;br&gt;&lt;br&gt;		#region public functionality&lt;br&gt;		public object GetObject( string typename, object[] ctorParms ){&lt;br&gt;			BindingFlags flags = BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public;&lt;br&gt;			object o = null;&lt;br&gt;			if( a != null ){&lt;br&gt;				try{&lt;br&gt;					o = a.CreateInstance( typename, true, flags, null, ctorParms, null, null );&lt;br&gt;				} catch (Exception){&lt;br&gt;					o = new ObjectLoadFailureException();&lt;br&gt;				}&lt;br&gt;			} else {&lt;br&gt;				o = new AssemblyNotLoadedException();&lt;br&gt;			}&lt;br&gt;			return o;&lt;br&gt;		}&lt;br&gt;		public object GetObject( string typename ){&lt;br&gt;			return GetObject( typename, null );&lt;br&gt;		}&lt;br&gt;		#endregion&lt;br&gt;&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;--- end cut&lt;br&gt;&lt;br&gt;</description></item><item><title>Why isn't there an Assembly.Unload method?</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#145106</link><pubDate>Tue, 01 Jun 2004 02:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:145106</guid><dc:creator>Jason Zander's WebLog</dc:creator><description /></item><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#171729</link><pubDate>Sat, 03 Jul 2004 07:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:171729</guid><dc:creator>andrei</dc:creator><description>I have the following problem:&lt;br&gt;I followed the steps described here, as well as anywhere i looked for documentation regarding this issue and the result is not quite what I expected. I obtain a shadow copy of my dll, but both files, the original and the shadow copied dll are locked by the process.&lt;br&gt;here is a piece of the code, please tell me what is wrong with it:&lt;br&gt;&lt;br&gt;					System.AppDomainSetup appDomainSetup = new AppDomainSetup();&lt;br&gt;&lt;br&gt;					appDomainSetup.ShadowCopyDirectories = &amp;quot;D:\\pathToMyApp\\bin\\Debug&amp;quot;;&lt;br&gt;					appDomainSetup.ShadowCopyFiles = &amp;quot;true&amp;quot;;&lt;br&gt;					appDomainSetup.CachePath = @&amp;quot;D:\\pathToMyApp\\bin\\Debug&amp;quot;;&lt;br&gt;					appDomainSetup.ApplicationName = &amp;quot;appName&amp;quot;;&lt;br&gt;					&lt;br&gt;					System.AppDomain appDomain = System.AppDomain.CreateDomain(&amp;quot;Domain&amp;quot; + &amp;quot;someName&amp;quot;,&lt;br&gt;						new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence), &lt;br&gt;						appDomainSetup);&lt;br&gt;&lt;br&gt;					System.Reflection.AssemblyName assemblyName = System.Reflection.AssemblyName.GetAssemblyName(&amp;quot;pathToTheDll&amp;quot;);&lt;br&gt;&lt;br&gt;					System.Reflection.Assembly assembly =	appDomain.Load(assemblyName);					&lt;br&gt;</description></item><item><title>re: AppDomain and Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#172195</link><pubDate>Sat, 03 Jul 2004 19:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:172195</guid><dc:creator>Junfeng Zhang</dc:creator><description>Please see Suzanne'blog about AppDomain.Load()&lt;br&gt;&lt;a target="_new" href="http://blogs.msdn.com/suzcook/archive/2003/06/16/57188.aspx"&gt;http://blogs.msdn.com/suzcook/archive/2003/06/16/57188.aspx&lt;/a&gt;&lt;br&gt;</description></item><item><title>Assembly.Unload</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#175972</link><pubDate>Thu, 08 Jul 2004 06:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:175972</guid><dc:creator>Flier's Sky</dc:creator><description>Assembly.Unload</description></item><item><title>sunnywizmudding: Shadow Copies of Assemblies</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#696867</link><pubDate>Sun, 13 Aug 2006 01:08:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:696867</guid><dc:creator>sunnywizmudding: Shadow Copies of Assemblies</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://www.livejournal.com/users/sunnywizmudding/4884.html"&gt;http://www.livejournal.com/users/sunnywizmudding/4884.html&lt;/a&gt;</description></item><item><title>Shadow Copies of Assemblies by sunnywizmudding () | LjSEEK.COM</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#696868</link><pubDate>Sun, 13 Aug 2006 01:08:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:696868</guid><dc:creator>Shadow Copies of Assemblies by sunnywizmudding () | LjSEEK.COM</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://www.ljseek.com/shadow-copies-of-assemblies_709543.html"&gt;http://www.ljseek.com/shadow-copies-of-assemblies_709543.html&lt;/a&gt;</description></item><item><title>Assembly.Unload </title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#4683070</link><pubDate>Sat, 01 Sep 2007 09:48:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4683070</guid><dc:creator>林西</dc:creator><description>&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.blogcn.com/user8/flier_lu/index.html?id=2164751"&gt;http://www.blogcn.com/user8/flier_lu/index.html?id=2164751&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>shadow copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#8709541</link><pubDate>Tue, 08 Jul 2008 22:53:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8709541</guid><dc:creator>shadow copy</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://aaliyah.onlinevidsworld.info/shadowcopy.html"&gt;http://aaliyah.onlinevidsworld.info/shadowcopy.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>AppDomain / ShadowCopy | hilpers</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#9336242</link><pubDate>Sat, 17 Jan 2009 20:47:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9336242</guid><dc:creator>AppDomain / ShadowCopy | hilpers</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.hilpers.com/1174545-appdomain-shadowcopy"&gt;http://www.hilpers.com/1174545-appdomain-shadowcopy&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>The Cave  &amp;raquo; Blog Archive   &amp;raquo; Shadow Copy</title><link>http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx#9410151</link><pubDate>Tue, 10 Feb 2009 11:54:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9410151</guid><dc:creator>The Cave  &amp;raquo; Blog Archive   &amp;raquo; Shadow Copy</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://kapustein.com/blog/?p=1170"&gt;http://kapustein.com/blog/?p=1170&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>