{"id":20851936,"url":"https://github.com/chaoses-ib/marshalbyrefproxy","last_synced_at":"2025-05-12T04:32:18.683Z","repository":{"id":65374802,"uuid":"591104384","full_name":"Chaoses-Ib/MarshalByRefProxy","owner":"Chaoses-Ib","description":"A .NET library for marshalling any object by reference that do not require the object to inherit from MarshalByRefObject.","archived":false,"fork":false,"pushed_at":"2023-01-25T06:22:33.000Z","size":119,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-27T00:18:42.647Z","etag":null,"topics":["appdomain","dotnet-remoting","marshal","marshalling"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chaoses-Ib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-19T23:32:39.000Z","updated_at":"2025-01-20T19:05:09.000Z","dependencies_parsed_at":"2023-02-14T05:16:40.828Z","dependency_job_id":null,"html_url":"https://github.com/Chaoses-Ib/MarshalByRefProxy","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chaoses-Ib%2FMarshalByRefProxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chaoses-Ib%2FMarshalByRefProxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chaoses-Ib%2FMarshalByRefProxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chaoses-Ib%2FMarshalByRefProxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chaoses-Ib","download_url":"https://codeload.github.com/Chaoses-Ib/MarshalByRefProxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253675652,"owners_count":21945950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appdomain","dotnet-remoting","marshal","marshalling"],"created_at":"2024-11-18T03:15:37.241Z","updated_at":"2025-05-12T04:32:18.415Z","avatar_url":"https://github.com/Chaoses-Ib.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MarshalByRefProxy\n[![NuGet](http://img.shields.io/nuget/v/MarshalByRefProxy.svg)](https://www.nuget.org/packages/MarshalByRefProxy)\n\nA .NET library for marshalling any object by reference that do not require the object to inherit from [MarshalByRefObject](https://learn.microsoft.com/en-us/dotnet/api/system.marshalbyrefobject).\n\nThis project is based on [ImpromptuInterface](https://github.com/ekonbenefits/impromptu-interface).\n\n## Basic usage\n```csharp\nusing MarshalByRefAsProxy;\n\npublic interface IProxyInterface\n{\n    string GetCurrentAppDomainName();\n}\n\n// UnmarshallableClass is not required to inherit from IProxyInterface.\n// Here we inherit from IProxyInterface just to be able to call CreateInstance() for comparison.\nclass UnmarshallableClass : IProxyInterface\n{\n    public string GetCurrentAppDomainName() =\u003e AppDomain.CurrentDomain.FriendlyName;\n}\n\nclass ClassFactory : MarshalByRefObject\n{\n    public IProxyInterface CreateInstance() =\u003e new UnmarshallableClass();\n\n    public IProxyInterface CreateMarshalByRefInstance() =\u003e new UnmarshallableClass().MarshalByRefAs\u003cIProxyInterface\u003e();\n}\n\n[Test]\npublic void TestCrossAppDomain()\n{\n    // Create an application domain named TestDomain\n    AppDomain domain = AppDomain.CreateDomain(\"TestDomain\");\n    ClassFactory factory = (ClassFactory)domain.CreateInstanceFromAndUnwrap(typeof(ClassFactory).Assembly.Location, typeof(ClassFactory).FullName);\n\n    // Try to marshal an unmarshallable object, which throws a SerializationException\n    Assert.Throws\u003cSerializationException\u003e(() =\u003e factory.CreateInstance().GetCurrentAppDomainName());\n\n    // Try to marshal an unmarshallable object via MarshalByRefProxy, which works fine\n    Assert.AreEqual(\"TestDomain\", factory.CreateMarshalByRefInstance().GetCurrentAppDomainName());\n}\n```\n\n## Task\n```csharp\nclass TaskTest : MarshalByRefObject\n{\n    // Cannot be an async method\n    // The return type cannot be IAwaitable\u003cT\u003e\n    public IAwaitable GetCurrentAppDomainNameAsync()\n    {\n        Task.Delay(1000).Wait();\n        // IAwaitable is defined by MarshalByRefProxy\n        return Task.Run(() =\u003e AppDomain.CurrentDomain.FriendlyName).MarshalByRefAs\u003cIAwaitable\u003e();\n    }\n}        \n\n[Test]\npublic async Task TestTask()\n{\n    AppDomain domain = AppDomain.CreateDomain(\"TestDomain\");\n    TaskTest test = (TaskTest)domain.CreateInstanceFromAndUnwrap(typeof(TaskTest).Assembly.Location, typeof(TaskTest).FullName);\n\n    string name = (string)await test.GetCurrentAppDomainNameAsync();\n    Assert.AreEqual(\"TestDomain\", name);\n}\n```\nWhy can we await `IAwaitable`? Because C# can await any [awaitable expressions](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#11882-awaitable-expressions), which is exactly what `IAwaitable` stands for.\n\n## Permissions (.NET Framework only)\nAssert unrestricted permissions:\n```csharp\nusing System.Security;\nusing System.Security.Permissions;\n\nnew UnmarshallableClass().MarshalByRefAs\u003cIProxyInterface\u003e(new PermissionSet(PermissionState.Unrestricted));\n```\n\n## Todos\n- [ ] `IAwaitable\u003cT\u003e`\n- [ ] MarshalByRefWrapper Code Generators\n- [ ] MarshalByRefObject Code Generators","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaoses-ib%2Fmarshalbyrefproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaoses-ib%2Fmarshalbyrefproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaoses-ib%2Fmarshalbyrefproxy/lists"}