Why AppDomain.ShadowCopyFiles is string?

1.2k views Asked by At

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?

1

There are 1 answers

0
StevieB On BEST ANSWER

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