SPC100206: Do not create static fields and properties |
Avoid creating static fields and properties in your sandboxed code.
CheckId | SPC100206 |
---|---|
TypeName | DoNotCreateStaticMembers |
Severity | Error |
Type | Assembly |
When a specific sandboxed solution is handled for the first time on a given server that is running the SharePoint Foundation Sandboxed Code Service (sometimes called the User Code Host Service), the service creates an application domain for it in a sandboxed worker process, and all static variables in the solution code are loaded into the domain. The application domain stays alive after the sandboxed solution finishes and is reused if that same sandboxed solution is requested again, perhaps by a different user on a different site collection. A side effect of this system is that the static values are not reloaded, and these values are not necessarily appropriate to every execution of the sandboxed solution in every context. For example, suppose the solution code puts SPContext.Current into a static field named myContext. If the same solution is requested from another site collection, the value of myContext.Site is incorrect.
To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.
[SuppressMessage("SPCAF.Rules.SandboxedCompatibilityGroup", "SPC100206:DoNotCreateStaticMembers", Justification = "Provide reason for suppression here")]