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 8079781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:13:10+00:00 2026-06-05T16:13:10+00:00

using System; using System.IO; using System.Reflection; using System.Text; using MyApp.Logging; namespace MyApp.SmsService.Common { public

  • 0
using System;
using System.IO;
using System.Reflection;
using System.Text;
using MyApp.Logging;

namespace MyApp.SmsService.Common
{
    public class MyAppAppDomain:MarshalByRefObject
    {
        private readonly AppDomainSetup domaininfo;
        private readonly AppDomain appDomain;
        public static string libDllPath;

        public MyAppAppDomain(string appDomainName) //Constructor
        {
            //Setup the App Domain Parameters
            domaininfo = new AppDomainSetup();
            domaininfo.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            domaininfo.DisallowBindingRedirects = false;
            domaininfo.DisallowCodeDownload = true;
            domaininfo.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            // Create the application domain.
            appDomain = AppDomain.CreateDomain(appDomainName, null, domaininfo);

            //Set the dll path using Static class ref.

            //Dependency resolution handler
            appDomain.AssemblyResolve += LoadFromLibFolder; /*Exception*/
        }

        private static Assembly LoadFromLibFolder(object sender, ResolveEventArgs args)
        {

            if (libDllPath != null)
            {
                string assemblyPath = Path.Combine(libDllPath, new AssemblyName(args.Name).Name + ".dll");

                if (File.Exists(assemblyPath) == false)
                {
                    return null;
                }
                Assembly assembly = Assembly.LoadFrom(assemblyPath);
                //Assembly dependancy resolved.

                return assembly;
            }

            return null;
        }

        public Object getNewInstanceOf(string fullyQualifiedTypeName)
        {
            return appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, fullyQualifiedTypeName);
        }

        public Type getTypeOf(string fullyQualifiedTypeName)
        {
            return getNewInstanceOf(fullyQualifiedTypeName).GetType();
        }

        public void unloadDomain()
        {
            AppDomain.Unload(appDomain);
        }
    }
}

The above class is a wrapper that I want to create to setup and teardown an application domain. However, in my webservice I am getting a FileNotFoundException [Failed to load a dll xyz.dll] whenever I am instantiating the object of MyAppAppDomain.

Following is the ex:

MyAppAppDomain.libDllPath = appDllLibPath; //Some directory other than bin.
pluginDomain = new MyAppAppDomain("SmsServicePlugins"); //Throws FileNotFoundException.

When I debug, I see that the line that caused the exception is the one marked above as /exception/, inside the constructor of MyAppAppDomain.

What is going wrong?

EDIT:

I was going through other articles and I read that objects cannot be visible across domains. This can only happen when the object can be serialized in both domains (use of MarshalByRefObject) and then can be accessed through proxies.

Would be of great help if someone can point out the issues in the above code. In the meanwhile I am attempting to learn more on Marshalling and Proxy-ing.

  • 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-06-05T16:13:12+00:00Added an answer on June 5, 2026 at 4:13 pm

    First problem is you are trying to doing everything inside app domain wrapper, it is really two different components. The first component you need is your object that you want to create inside your new app domain which inherits from MarshalByRefObject (or marked as Serializable). The other lives inside your current AppDomain and is used to create the new AppDomain.

    Have a look at the msdn example to see what I mean.

    However your error is probably more than likely that your path is wrong to your DLL. Could you show the full stack trace to show what line is throwing the exception?

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

Sidebar

Related Questions

How can I generate types like these using the System.Reflection.Emit libraries: public class Test<T>
using System; public sealed class Singleton { private static volatile Singleton instance; private static
using System; using System.Linq; using System.Text; using System.Net; using System.IO; namespace LearningJustCode { class
using System; namespace MergeSort { class Program { static int[] vektor = { 5,
I have a program which write logging as Text File. namespace logging { using
I need to do this:- MyClass.cs using System; using System.Collections.Generic; using System.Text; namespace set_property__Enum_To_Nullable_Enum
I am using System.Reflection to load a type that I cannot otherwise load during
I'm generating wrappers for types by using System.Reflection.Emit . At one point it's possible
using System; using System.Drawing; using System.IO; using System.Security.Cryptography; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Threading;
using System; using System.Collections.Generic; using Newtonsoft.Json; using System.Text; using System.IO; using System.Runtime.Serialization; using Newtonsoft.Json.Serialization;

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.