none
AppDomain ShadowCopy seems to not work RRS feed

  • Question

  • Why does this crash at the last line?

                AppDomainSetup appDomainSetup = new AppDomainSetup();
                appDomainSetup.ShadowCopyFiles = "true";
                AppDomain myDomain = AppDomain.CreateDomain("MyAppDomain", null, appDomainSetup);
                Assembly myLoadedAssembly = myDomain.Load("MyAssembly");
                File.Delete(myLoadedAssembly.Location);

    EDIT1: Additional info: System.UnauthorizedAccessException ("Access to the path '<the path>' is denied."). When the process is stopped I can delete from Explorer, so no strange security settings.

    EDIT2: Additional info:The file is actually copied to a folder in the user profile and that one is also locked (while AppDomain still loaded)

    EDIT3: Even if I unload (AppDomain.Unload(myDomain)) immediately after creation/loading it is still locked.


    • Edited by EuroEager Sunday, July 22, 2018 12:53 PM
    Sunday, July 22, 2018 10:22 AM

All replies

  • Hi EuroEager,

    Thank you for posting here.

    According to your description, you seem to configure Current AppDomain to enable Shadow Copying Assemblies. Please refer to the samples in Code project, it provide different scenarios without the assembly file to be locked. 

    https://www.codeproject.com/Tips/836907/Loading-Assembly-to-Leave-Assembly-File-Unlocked

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 23, 2018 7:15 AM
    Moderator
  • Thanks

    Perhaps I fundamentally misunderstand the concept of app domains.
    What I try to achieve is that I want to load an assembly and run some code from there.
    The requirement is that this assembly must be possible to unload and being re-loaded with a newer version.
    To do this the assembly must be loaded in another AppDomain and the whole domain must be unloaded and recreated etc. when needed.

    I thought this can be down with a class library (dll) assembly, but seemingly not.
    (The assembly is indeed loaded into the new AppDomain, but also in the current AppDomain which explains the lock, and the code started by starting a (WCF) ServiceHost based on a type from the loaded assembly, will not be executed in the new AppDomain, but in the current one.

    I can make it working if the loaded assembly is an exe (e.g. console app) and with statement MyAppDomain.ExecuteAssembly, but I haven't managed to configure correct.
    What I want is actually to configure WCF services in both the "loading" AppDomain and the "loaded" AppDomain and both shall use the same base address (e.g. net.tcp://localhost:34567).
    Does clr "merge" the config files for the 2 apps? Are the apps working totally separately so common base address is not possible?

    EDIT: Even if a little off topic (not directly related to shadow copy): Is there one dedicated "transport manager" for each AppDomain which do not cooperate regarding "portsharing" between different AppDomains in same process?
    • Edited by EuroEager Monday, July 23, 2018 6:12 PM
    Monday, July 23, 2018 11:47 AM