Skip to content

Consider Reloadable Attribute for Hot Reload  #54633

@tommcdon

Description

@tommcdon

Background and Motivation

Roslyn is adding a Reloadable Type feature. Types marked with the Reloadable attribute instructs the Roslyn compiler to emit a new type rather than updating it when applying changes with .NET Hot Reload. This feature enables inner-dev loop changes to be made that normally would be considered to be rude edits. We are proposing the Reloadable attribute to be used by frameworks, 3rd party libraries, and end users. It will be consumed by the Roslyn compiler.

Proposed API

namespace System.Runtime.CompilerServices
{  
  [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]  
  public class ReloadableAttribute : Attribute  
  {  

  }
}

Usage Examples

MyUIFramework knows how to serialize, instantiate, reinitialize, and display onscreen any View subclass. So even 'rude edits' that ends up being new version of types can be applied by MyUIFramework during a .NET Hot Reload session.

namespace MyUIFramework
{
  [Reloadable]
  public class View
  {

  }
}

Alternative Designs

  1. One alternative would be to the add known types at the Roslyn level, though this limits future extensibility by 3rd parties and app developers.

  2. Another alternative is to define an internal attribute for each framework that supports the reloadable type feature. The disadvantage is that there are possible conflicts when using InternalVisibleTo, and a lack of central documentation of the feature.

Risks

None at the runtime library level, as this only defines an attribute

UPDATE:
ReloadableAttribute renamed to CreateNewOnMetadataUpdateAttribute

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions