3

I have four assemblies, ModuleStatic, Loader and ModuleA and ModuleB, all of them are DLL besides Loader which is an executable.

In DLL ModuleStatic:

public class ModuleStatic {
    public static string Foo { get; set; } = "Foo";    
}

In Loader, ModuleA and ModuleB will be loaded through Assembly.Load and AppDomain, to domA and domB respectively. If ModuleA modified the ModuleStatic.Foo variable, will the ModuleB, which is in domB, receive the modification?

Steve Fan
  • 3,019
  • 3
  • 19
  • 29

1 Answers1

5

No, variables, static or not, will not be shared across AppDomains. Instances live within their own AppDomain, they won't cross unless you do some work for it, for example by making it MarshalByRefObject and copy the static 'instance' around.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • ...or when the types containing the static fields/properties are marked as `[Serializable]` – tommed Jun 08 '17 at 20:25