6

There is ShadowCopy functionality in .Net to preserve file locking by copying assemblies. There are two properties:

  1. AppDomain.ShadowCopyFiles that uses AppDomainSetup
  2. AppDomainSetup.ShadowCopyFiles that stores it in internal string[]

AppDomainSetup has string Value[] field, that used for storing configuration. The strange thing for me is that AppDomainSetup.ShadowCopyFiles is a string property, and we need to set "true" or "false" instead of real bool type.

Here is an implementation for that property in AppDomainSetup:

public string ShadowCopyFiles
{
  get
  {
    return this.Value[8];
  }
  set
  {
    if (value != null && string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
      this.Value[8] = value;
    else
      this.Value[8] = (string) null;
  }
}

And here is an implementation for AppDomain.ShadowCopyFiles:

public bool ShadowCopyFiles 
{ 
    get {
        String s = FusionStore.ShadowCopyFiles; 
        if((s != null) &&
           (String.Compare(s, "true", StringComparison.OrdinalIgnoreCase) == 0))
            return true;
        else 
            return false;
    } 
} 

But why in AppDomainSetup this property is a string? Why Microsoft didn't used the some bool conversion logic as in AppDomain.ShadowCopyFiles?

It strange that such a bit smelly code located in AppDomainSetup, and I was just thinking is there a real reason for that that I'm missing?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67
  • 1
    possible duplicate of [Why is AppDomainSetup.ShadowCopyFiles a string?](http://stackoverflow.com/questions/1862434/why-is-appdomainsetup-shadowcopyfiles-a-string) – Despertar May 29 '14 at 04:47

1 Answers1

9

It was a mistake in the early versions of .NET and MS have decided not to fix it as it would break existing code.

See this link.

http://connect.microsoft.com/VisualStudio/feedback/details/295269/appdomainsetup-shadowcopyfiles-should-be-of-the-type-bool-instead-of-string

StevieB
  • 982
  • 7
  • 15