Bug 56821 - Static ctor of MarshalByRefObject runs in primary AppDomain
Summary: Static ctor of MarshalByRefObject runs in primary AppDomain
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-25 00:14 UTC by Kirill Osenkov
Modified: 2017-06-02 15:58 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Kirill Osenkov 2017-05-25 00:14:02 UTC
I'm using Mono 5.2.0.127 on Windows.

Consider this C# program:
=========================
using System;

class Program
{
    static void Main(string[] args)
    {
        var appDomain = AppDomain.CreateDomain("Test Domain", null, AppDomain.CurrentDomain.SetupInformation);
        var driver = (Remote)appDomain.CreateInstanceAndUnwrap(
            typeof(Remote).Assembly.FullName,
            typeof(Remote).FullName);
        driver.Test();
    }
}

class Remote : MarshalByRefObject
{
    static Remote()
    {
        Console.WriteLine($"cctor in AppDomain {AppDomain.CurrentDomain.FriendlyName}");
    }

    internal void Test()
    {
    }
}

=========================

If you compile and run this C# file on .NET Framework, the output is:

cctor in AppDomain Test Domain

If you run it on Mono, the output is:

cctor in AppDomain Test Domain
cctor in AppDomain CrashMono.exe

Not sure if this behavior is by design, but I thought I'd check just in case. Why is the cctor not running in the primary appdomain for .NET Framework but is running on Mono?

I'm noticing another discrepancy, not sure if related:

Assembly.Load("System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); loads three assemblies on .NET (System.Windows.Forms, System and System.Drawing) but only one assembly on Mono (System.Windows.Forms)
Comment 1 Zoltan Varga 2017-05-30 20:58:51 UTC
https://github.com/mono/mono/pull/4950
Comment 2 Zoltan Varga 2017-06-02 15:58:07 UTC
Fixed in master/2017-04.