Bug 44707

Summary: RemotingConfiguration.Configure() Throws RemotingException Because it Cannot Load 'machine.config'
Product: [Desktop] Xamarin.Mac Reporter: Jimmy [MSFT] <jimmy.garrido>
Component: Base Class LibrariesAssignee: Chris Hamons <chris.hamons>
Status: VERIFIED FIXED    
Severity: normal CC: abock, chris.hamons, kumpera, mohitk, mono-bugs+monomac, mono-bugs+mono, naqeeba, prashantm, sachins, sandy, sebastien
Priority: ---    
Version: Master   
Target Milestone: (C9)   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: repro project

Description Jimmy [MSFT] 2016-09-23 22:25:26 UTC
Created attachment 17724 [details]
repro project

#### Overview
Calling RemotingConfiguration.Configure() will cause the app to crash with

> System.Runtime.Remoting.RemotingException: Configuration file '/Users/builder/data/lanes/3508/c1e5fa01/source/xamarin-macios/builds/install/mac64/etc/mono/4.5/machine.config' could not be loaded: Could not find a part of the path "/Users/builder/data/lanes/3508/c1e5fa01/source/xamarin-macios/builds/install/mac64/etc/mono/4.5/machine.config".

Full stack trace: https://gist.github.com/jimmgarrido/766fa1c992859e430a92b6de67234873


### Steps to Reproduce
1. Run the attached repro project


### Expected Results
The app will launch.


### Actual Results
The app crashes immediately after launching.


### Version Info
=== Xamarin Studio Enterprise ===

Version 6.1 (build 5441)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.34.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 7.0.0.18 (Visual Studio Enterprise)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 24.0.2
SDK Build Tools Version: 24.0.2

Java SDK: /usr
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 8.0 (11246)
Build 8A218a

=== Xamarin.Mac ===

Version: 2.10.0.99 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 10.0.0.6 (Visual Studio Enterprise)
Hash: 6c3fee4
Branch: xcode8
Build date: 2016-09-09 13:01:32-0400

=== Build Information ===

Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.11.6
Darwin Jimmys-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Redth's Addins 1.0.2
Comment 1 Chris Hamons 2016-09-26 18:20:10 UTC
The root cause of this is that here:

https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L7178

we are not getting the right path for bundled XM applications.

I'm not sure the correct fix, but it might involve mono changes.



If you are willing to traffic in implementation specific hacks, this appears to "workaround" the issue

https://gist.github.com/chamons/f5de79eccc1aa775daa528da6aa17af3

by using reflection to "do the right thing".
Comment 2 Chris Hamons 2016-10-04 16:52:30 UTC
I'm thinking this was caused by https://github.com/mono/mono/commit/c1a732c45276e2273ce295bac99cf3fb920b772b
Comment 3 Chris Hamons 2016-10-04 17:00:04 UTC
No, ^ was in C8 but this exception was against C8 so can't be it.
Comment 4 Chris Hamons 2016-10-04 17:03:23 UTC
Does Xamarin.Mac need to pass in a different config file (we'd need an API to do that, see my comment on  https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L7178) above? 

or 

is this a bug/behavior change in mono?
Comment 6 Rodrigo Kumpera 2016-10-05 01:12:56 UTC
As a workaround, set the MONO_CFG_DIR to a directory with a readable machine.config.

This is not a regression, AFAICT,  as this behavior exists for quite some time.
Comment 8 Chris Hamons 2016-10-10 16:48:30 UTC
https://github.com/xamarin/xamarin-macios/pull/971
Comment 11 Chris Hamons 2016-10-14 18:12:12 UTC
Please retest after 84e9975e41f48e2444d233eda64112377856276c.

AND/OR

Add this to additional mmp arguments:

--machine-config=""       # Yes, two double quotes w\ nothing in it

When we bumped to latest, we should have picked up mono's "real" fix.

My commit just adds a backup option in mmp to work around it \ other use cases that require the file.

Sorry for not being clear.
Comment 13 Chris Hamons 2016-10-18 15:51:01 UTC
Could you zip up your bundle and build log and attach?
Comment 15 Chris Hamons 2016-10-18 17:09:37 UTC
The combination of my fix + mono's broke it. Looking into it...
Comment 16 Chris Hamons 2016-10-18 20:40:01 UTC
Ok, we needed to bump mono again to get working after the first mono bump.

QA - Please retest against the very latest XM (3e1204278baa060c45f3a876492f91bd5582d3c5 or greater). Please note (which I forgot first time) that you will need to remoting.config's build action to BundleResource for things to work at all.
Comment 17 Mohit Kheterpal 2016-10-19 06:05:55 UTC
Thanks @Chris

I have checked this issue after setting build action of remote.config's file to Bundleresource with latest build of MonoFramework-MDK-4.8.0.245.macos10.xamarin.universal_8be6ecc66f4c295a61dc5b5677794929731d05d6 + xamarin.mac-3.0.0.137_3e1204278baa060c45f3a876492f91bd5582d3c5 and observed that this issue has been fixed.

screencast : http://www.screencast.com/t/VLCgezD7

thanks
Comment 18 Naqeeb 2016-10-28 04:41:21 UTC
I have checked this issue with latest master build and observed that it is working fine after changing Build Action to BundleResource of remote.config's file . Here is the screencast for the same: http://www.screencast.com/t/uaLYLVfFC7

Environment info: https://gist.github.com/NaqeebAnsari/8f81887cca481f1a711ec07228b390da