Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are static class shared between AppDomain? [duplicate]

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?

like image 788
Steve Fan Avatar asked Oct 24 '25 17:10

Steve Fan


1 Answers

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.

like image 179
Patrick Hofman Avatar answered Oct 26 '25 06:10

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!