0

Good morning, I am working on a simple ASP.net application. I have implemented some code which is in C# dlls. Those dlls are used and loaded by the ASP.net application. The goal is to put the C# dlls outside of the project, in a specific folder, (for example C:\users\Dlls) and use them in the ASP.net application. When I debug in Visual, I saw that there are different application domains. For what I understand, the first application domain is the default one : 'iisexpress.exe' (CLR v4.0.30319: DefaultDomain)

And after that I have another one :

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-1-132768598652050662)

I have made some code with using assembly resolver system to load my own assemblies in the second application domain (/LM/W3SVC/2/ROOT-1-132768598652050662) and it works fine.

Now, I would like to load my own assemblies in the application domain called "DefaultDomain" but I did not succeed it. I have tried assembly resolver but it does not work.

For debugging, in order to have a list of which assemblies are load by "DefaultDomain", I have used this following method :

private static AppDomain GetAppDomain(string friendlyName)
{
   IntPtr enumHandle = IntPtr.Zero;
   ICorRuntimeHost host = new CorRuntimeHost();
   try
   {
      host.EnumDomains(out enumHandle);
      object domain = null;
      while (true)
      {
        host.NextDomain(enumHandle, out domain);
        if (domain == null)
        {
          break;
        }
        AppDomain appDomain = (AppDomain)domain;
        if (appDomain.FriendlyName.Equals(friendlyName))
        {
          return appDomain;
        }
      }
    }
    finally
    {
       host.CloseEnum(enumHandle);
       Marshal.ReleaseComObject(host);
       host = null;
    }
  return null;
}

I get the list of assemblies with that :

AppDomain appDefaultDomain = GetAppDomain("DefaultDomain");
Assembly[] tabAssembliesAppDomain = appDefaultDomain.GetAssemblies();

With debugging, I have check the setup information of the "DefaultDomain" :

enter image description here

I am wondering if I change the "ApplicationBase", "PrivateBinPath" or "PrivateBinPath" fields it could resolve the problem but I think it is a part from a configuration of IIS server. Also I see that there is a configuration file iisexpress.exe.config but it doesn't exist. Maybe I have to create one but I don't know how to do it.

Thank you in advance for any help.

Zaraki21
  • 21
  • 1
  • 4
  • Stop wasting your time, https://stackoverflow.com/questions/42284444/does-asp-net-ever-run-in-the-default-appdomain/42287435 You are not supposed to use that default domain. – Lex Li Sep 24 '21 at 23:18
  • Not at all sure why this is an issue. You are free to referance the assembies - even ones outside of hte project. Of course when you build the project, then any and all required .dlls will be copied and placed in the bin folder. So, it not at all clear why those assemblies are not being included when you build the application. Now, in place of a web application, then this may well be a web site and thus you simple have to copy the .dlls to the bin file. But, if this is a web application, then you should not have to do anything more then just reference those .dlls in the current project. – Albert D. Kallal Sep 24 '21 at 23:22
  • Ok for not using the default domain. The main issue is that I have to put the Dlls in C:\Program Files\IIS Express\ in order to load them. The project I am working on is for clients who do not want to put Dlls in this folder and want to put them in a separate one. This folder is indeed on the C:\. It seems strange to me that there isn't a way to set this up. – Zaraki21 Sep 27 '21 at 07:23

0 Answers0