Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6020737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:36:42+00:00 2026-05-23T03:36:42+00:00

I’ve written a very basic web server in C# that loads custom modules that

  • 0

I’ve written a very basic web server in C# that loads custom modules that handle requests to a specific domain name, as specified in a config file. The custom modules are loaded into a new AppDomain because I need the ability to unload them dynamically (good for security, too). Because modules are loaded into a new AppDomain all parameters and return types are MarshalByRefObject. This works fine and I pass a HttpRequest object that inherits from MarshalByRefObject and return a LinkedList that is sent back to the client by the web server.

All of this works well, but a lot of the data is passed as byte[] and I believe the proxy for MarshalByRefObject will copy all of the bytes from the new AppDomain to the main AppDomain instead of accessing them directly. So, if I’m right about this, if one of the modules would send a 5MB file as a response then 5MB would be loaded/generated in the module, then copied from the modules AppDomain to the main AppDomain and finally sent through the socket back to the client.

So, my question is: can I get around this somehow so it doesn’t copy so much data between AppDomain’s? Or is there a better way to do this that doesn’t use MarshalByRefObject?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:36:43+00:00Added an answer on May 23, 2026 at 3:36 am

    I ended up passing the SocketInformation to the new AppDomain and creating a new socket object there (in the new AppDomain).

    In my “Sandbox wrapper object” I have this function:

    internal class Sandbox
    {
        private AppDomain _AppDomain;
        private WebApplicationProxy _Proxy;
    
        public Sandbox(string assemblyFile)
        {
            _AppDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString());
            _Proxy = (WebApplicationProxy)_AppDomain.CreateInstanceAndUnwrap(
                                                        Assembly.GetExecutingAssembly().FullName,
                                                        "WebServer.WebApplication.Proxy");
            _Proxy.Initialize(assemblyFile);
        }
        public void SendResponse(Socket client, HttpRequest request)
        {
            SocketInformation clientInfo = client.DuplicateAndClose(Process.GetCurrentProcess().Id);
            _Proxy.GetResponse(clientInfo, request);
        }
    }
    

    And in the new AppDomain “resumes” the socket, I’m not sure yet what actually happens behind the scenes… here’s the code:

    internal class Proxy : MarshalByRefObject
    {
        private AppController _AppController;
    
        public void Initialize(string assemblyFile)
        {
            Assembly asm = Assembly.LoadFile(assemblyFile);
            var q = from t in asm.GetTypes()
                    where t.GetInterfaces().Contains(typeof(AppController))
                          && !t.IsAbstract && t.IsClass
                    select t;
            foreach (Type t in q)
            {
                _AppController = (AppController)Activator.CreateInstance(t);
            }
        }
    
        public void SendResponse(SocketInformation clientInfo, HttpRequest req)
        {
            Socket client = new Socket(clientInfo);
    
            LinkedList<byte[]> toSend = _AppController.GetResponse(client, req);
    
            foreach (byte[] bytes in toSend)
                client.Send(bytes);
    
            client.Close();
        }
    }
    

    I’m not sure about the details of what happens when DuplicateAndClose is invoked, or creating the new Socket object in the new domain, but it is working well so far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.