次の方法で共有


Assembly.CodeBase vs. Assembly.Location

The CodeBase is a URL to the place where the file was found, while the Location is the path from where it was actually loaded. For example, if the assembly was downloaded from the internet, its CodeBase may start with "https://", but its Location may start with "C:\". If the file was shadow copied, the Location would be the path to the copy of the file in the shadow-copy dir.

It’s also good to know that the CodeBase is not guaranteed to be set for assemblies in the GAC. Location will always be set for assemblies loaded from disk, however.

Comments

  • Anonymous
    June 26, 2003
    The comment has been removed
  • Anonymous
    June 27, 2003
    The comment has been removed
  • Anonymous
    June 27, 2003
    Lets say that I have an assembly that reads in config settings from a configuration file and shadow copying is enabled. The class that uses the configuration file assumes that the file is in the same directory as the assembly, which in this case would be the location where the assembly was shadow copied. Since the shadow copy process only copies the file that the assembly is in and not any external files (such as the config file), how can I make sure that the config file is copied along with the assembly file, when shadow copying is enabled. I could have the class read in the config file location from a registry key, but that is so 1997....
  • Anonymous
    June 30, 2003
    If this is regarding the app.config for the appdomain: the AppDomain could be set up in such a way that shadow-copying a local config file would be unnecessary (AppDomainSetup.ConfigurationFile could be set its location, or it could be the process exe's config file for the default case.) Then, your assembly could just get that appdomain's ConfigurationFile property.If this is a per-assembly config file, it could be included in that assembly as a non-manifest-containing module of a multi-file assembly. Then, it would be shadow-copied with the assembly. (An easy way to make your compiler emit this is to make it a linked ManifestResource.)
  • Anonymous
    September 21, 2006
    Is it possible to tell if the calling assembly is a Webforms app or console app, or a web application?

    I'm thinking in terms of a class that accesses things such as the local machines sound api's.

    Obviously we wouldn't want want web apps to access this class.

    Many thanks for your help
  • Anonymous
    February 19, 2007
    Hi, I have webservice application that uses some assemblies whoes version number keeps changing and are stored in some folder on the same machine as my webservice. Every Time the assembly version changes i need to change the binding redirect and code base in the web.config file.   EX : <dependentAssembly> <assemblyIdentity name="ABCD" publicKeyToken="Sometoken" culture="neutral" /> <bindingRedirect oldVersion="1.0.0.0-99999.99999.99999.99999" newVersion="1.0.1445.38584" /> <codeBase version="1.0.1445.38584" href="file:///C:Program FilesTPAABCD.dll" /> </dependentAssembly> Updating the web.config file is done when a particular webmethod is called. This thing works in development time,  because the version number in the config was same as the actual assembly, In production system this doesn't not work as the assembly version is different then config file and gives internal Error 500. I tired restarting IIS and deleting the web service Application folder from C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files Nothing worked :(
  1. What happens onces the webmethod is called , the webservices loads the assemblies based on the config file?
  2. Reinstalling the webservice seems the only current solution to update the config file. In what other way can i update the config file? Many Thanks, Regards Gauls
  • Anonymous
    October 22, 2009
    The comment has been removed