1

I've been trying to get this to work for about 4 hours now. The try catches the exception and it's `System.InvalidCastException: Unable to cast transparent proxy to type 'Test.SandboxDomain'.

What have I tried? Attaching to AppDomain.CurrentDomain.AssemblyResolve, however it never got called, I tried doing appDomain.CreateInstanceFrom() too, it didn't work, aswell as appDomain.CreateInstanceFromAndUnwrap().

   public static AppDomain CreateAppDomain()
    {
       return AppDomain.CreateDomain("AppDomain");
    }


    public static SandboxDomain CreateSandbox()
     {
        var appDomain = CreateAppDomain();

        AppDomain.CurrentDomain.AssemblyResolve += SandboxDomain.CurrentDomain_AssemblyResolve;

        string AssemblyPath = Assembly.GetExecutingAssembly().Location;

        SandboxDomain sandbox = null;
        try
        {
             sandbox = (SandboxDomain)Activator.CreateInstanceFrom(appDomain, AssemblyPath,
                                                      typeof(SandboxDomain).FullName).Unwrap();
        }
        catch (Exception ex)
        {
                    Console.WriteLine(ex); 
        }

       return sandbox;
    }

I've also tried this

stuck
  • 11
  • 2
  • Happens when the SandboxDomain type came from different assemblies. Rick Strahl has a [good blog post](https://weblog.west-wind.com/posts/2012/Jan/13/Unable-to-cast-transparent-proxy-to-type-type) about it, using Fuslogvw.exe is the primary weapon. – Hans Passant Feb 27 '19 at 07:22

0 Answers0