473,508 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I disable shadow copying for my assembly?

I have a component that needs to access files which exist in the same
directory as the DLL containing the component itself. To determine the
component's installation directory, I'm using
System.Reflection.Assembly.GetExecutingAssembly(). Location. This worked fine
on my computer, but for another user, it failed because the assembly was
being loaded using a shadow copy of the DLL located in a different directory.
Is there a way, programmatically, to determine the location of the original
DLL, or is there a way to turn off shadow copying?

Thanks,
Bill
Aug 10 '05 #1
5 7387
You could try:

AppDomain.CurrentDomain.BaseDirectory

I'm not sure if this will work though as I have never tired it.

--
Brian Delahunty
Ireland

http://briandela.com/blog
"Bill Rust" wrote:
I have a component that needs to access files which exist in the same
directory as the DLL containing the component itself. To determine the
component's installation directory, I'm using
System.Reflection.Assembly.GetExecutingAssembly(). Location. This worked fine
on my computer, but for another user, it failed because the assembly was
being loaded using a shadow copy of the DLL located in a different directory.
Is there a way, programmatically, to determine the location of the original
DLL, or is there a way to turn off shadow copying?

Thanks,
Bill

Aug 10 '05 #2
Hi Bill,

Thanks for your post.

Based on my understanding, your assembly DLL access files relative to its
directory. However, if the user loads your assembly DLL with shadow copy
feature, because the files will not be copied to the cache directory, the
assembly can not find the files any more. If I misunderstand you, please
feel free to tell me.

Normally, we use AppDomainSetup to set the shadow copy function for our
AppDomain. In our appdomain, all the shadow copy process has been over, so
it is impossible to disable it now. However, we can use
AppDomain.CurrentDomain.SetupInformation property to get the AppDomainSetup
reference, then we can use AppDomainSetup.ShadowCopyDirectories to get the
directory names our assembly original reside. Also, we can use
AppDomainSetup.CachePath property to get the cached shadow copy directory.

Hope this helps.
================================================== ==
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Aug 11 '05 #3
Hi Bill,

Does my reply make sense to you? If you still have any concern, please feel
free to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Aug 16 '05 #4
Hi Jeffrey,

Your reply makes sense, but I'm not sure it solves my problem because it
just tells me which directories are being shadow copied, but it doesn't tell
me which directory my component came from. At any rate, a co-worker informed
me of a different solution which appears to work. Rather than calling
System.Reflection.Assembly.GetExecutingAssembly(). Location, I call
System.Reflection.Assembly.GetExecutingAssembly(). CodeBase which gives me the
install directory.

Thanks,
Bill

""Jeffrey Tan[MSFT]"" wrote:
Hi Bill,

Does my reply make sense to you? If you still have any concern, please feel
free to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Aug 16 '05 #5
Hi Bill,

Thanks for your feedback.

Yes, System.Reflection.Assembly.GetExecutingAssembly(). CodeBase should meet
your need, it will return the original assembly location.

However, I think the solution I provided in the last reply should also get
what you want. Once we have used AppDomainSetup.ShadowCopyDirectories to
get where the assembly is shadown copied from, we can just add the assembly
dll name to this directory to get its original location, this should be the
same as what System.Reflection.Assembly.GetExecutingAssembly(). CodeBase
returns.

Because Asp.net used shadow copy technology, we can do the test in an
Asp.net application. I print out the different path with the code snippet
below:
private void Page_Load(object sender, System.EventArgs e)
{
this.Response.Write(AppDomain.CurrentDomain.BaseDi rectory+"<br>");

this.Response.Write(AppDomain.CurrentDomain.Shadow CopyFiles.ToString()+"<br>
");

this.Response.Write(AppDomain.CurrentDomain.SetupI nformation.CachePath.ToStr
ing()+"<br>");

this.Response.Write(AppDomain.CurrentDomain.SetupI nformation.ShadowCopyDirec
tories.ToString()+"<br>");

this.Response.Write(System.Reflection.Assembly.Get ExecutingAssembly().CodeBa
se+"<br>");
// Put user code to initialize the page here
}
On my machine, the output is:

c:/inetpub/wwwroot/webapp/shadowcopytest/
True
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Tempo rary ASP.NET
Files\webapp_shadowcopytest\7a027e7d
c:\inetpub\wwwroot\webapp\shadowcopytest\bin
file:///c:/inetpub/wwwroot/webapp/shadowcopytest/bin/shadowcopytest.DLL

As we can see, we can add
AppDomain.CurrentDomain.SetupInformation.ShadowCop yDirectories with the dll
file name to get the original assembly location full path.

Hope this clarify my point.
================================================== =====
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Aug 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2374
by: Mr 071 | last post by:
I am trying to use shadow copying provided by the framework, but I am not able to get it to work. More specifically, after a new app domain is created and the assembly loaded in it, it is still not...
4
4186
by: Barry Kelly | last post by:
I'm designing an application framework which will, amongst other things, live in an assembly hosted in the ASP.NET worker process, servicing webservice requests. Here's the scenario: APPFX is...
0
1717
by: Damien Anselmi | last post by:
I am using the CompileAssemblyFromSource method of an ICodeCompiler instance to dynamically compile an assembly used by a Web Application. The assembly may be recompiled any number of times during...
5
337
by: Bill Rust | last post by:
I have a component that needs to access files which exist in the same directory as the DLL containing the component itself. To determine the component's installation directory, I'm using...
2
2678
by: Oenone | last post by:
I have an application which loads plugin DLLs from various directories on the local disk. To avoid problems with the DLLs being locked by IIS, I have modified my code so that it copies the DLLs to...
0
1710
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
1
8908
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
5
3902
by: mark_overstreet | last post by:
I have a generic data layer DLL that expects to read its connection string from it's own config file. The dll and config file have been placed in the bin directory (VS.NET2005). However, due to...
0
1343
by: Mark | last post by:
I have a generic data layer DLL that expects to read its connection string from it's own config file located in the same directory (works great for winforms apps). The dll and config file have...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.