-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed as not planned
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-AssemblyLoader-coreclr
Description
Background and motivation
It would be nice to load Assembly from just a .cs file, this would easily allow new kind of add-ons to be developed,
Assembly.LoadFrom(myassembly.cs)
API Proposal
Assembly.LoadFrom(myassembly.cs)
API Usage
using System;
using System.Reflection;
// Assume you have an interface defined in a shared project
public interface IPlugin
{
void Run();
}
// In your main application code:
string assemblyPath = "C:\path\to\MyLibrary.dll";
string fullClassName = "MyNamespace.MyClass"; // Full name including namespace
try
{
// Load the assembly from the file path
Assembly assembly = Assembly.LoadFrom(assemblyPath);
// Get the Type information for the specific class
Type type = assembly.GetType(fullClassName);
if (type != null && typeof(IPlugin).IsAssignableFrom(type))
{
// Create an instance of the class
object instance = Activator.CreateInstance(type);
// Cast it to the shared interface and use it
IPlugin plugin = (IPlugin)instance;
plugin.Run();
}
else
{
Console.WriteLine($"Class {fullClassName} not found or does not implement IPlugin.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error loading assembly or creating instance: {ex.Message}");
}
Alternative Designs
No response
Risks
No response
omariom and lakani
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-AssemblyLoader-coreclr
Type
Projects
Status
No status