Bug 43646 - MTOUCH: Error MT2002: Failed to resolve "System.Int32 System.Runtime.InteropServices.Marshal::GetHRForException(System.Exception)" reference from "System.Runtime.InteropServices, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" (MT2002)
Summary: MTOUCH: Error MT2002: Failed to resolve "System.Int32 System.Runtime.InteropS...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 9.8 (tvOS / C7)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: 10.0.0 (C8)
Assignee: Marek Safar
URL: https://github.com/ghuntley/repros/tr...
Depends on:
Blocks:
 
Reported: 2016-08-23 06:03 UTC by Geoffrey Huntley
Modified: 2016-08-29 17:03 UTC (History)
7 users (show)

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


Attachments
Cycle 7 - iOS Release Build (Device) - Build Logs (141.41 KB, text/plain)
2016-08-23 06:03 UTC, Geoffrey Huntley
Details


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 Developer Community or GitHub 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:
VERIFIED FIXED

Description Geoffrey Huntley 2016-08-23 06:03:54 UTC
Created attachment 17168 [details]
Cycle 7 - iOS Release Build (Device) - Build Logs

# Repro

1) Clone https://github.com/ghuntley/repros/tree/master/xamarin/GetHRForException
2) Compile iOS Device Release build using Xamarin.Stable (Version: 9.8.2.22 (Cycle 7))
3) #fail
4) Compile iOS Device Release build using Xamarin.Beta (Version: 9.99.3.8 (Cycle 8))
5) #also #fail

# Notes

Does not happen on Debug|Simulator or Release|Simulator
Comment 1 Geoffrey Huntley 2016-08-23 06:05:18 UTC
		Linking SDK only for assembly /Users/ghuntley/Dropbox/OSS/repros/xamarin/SerilogRepro/iOS/bin/iPhone/Release//SerilogRepro.iOS.exe into /Users/ghuntley/Dropbox/OSS/repros/xamarin/SerilogRepro/iOS/obj/iPhone/Release/mtouch-cache/64/PreBuild
MTOUCH: error MT2002: Failed to resolve "System.Int32 System.Runtime.InteropServices.Marshal::GetHRForException(System.Exception)" reference from "System.Runtime.InteropServices, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
			Failed to resolve System.Int32 System.Runtime.InteropServices.Marshal::GetHRForException(System.Exception)
	Task "MTouch" execution -- FAILED
	Done building target "_CompileToNative" in project "/Users/ghuntley/Dropbox/OSS/repros/xamarin/SerilogRepro/iOS/SerilogRepro.iOS.csproj".-- FAILED
	
Done building project "/Users/ghuntley/Dropbox/OSS/repros/xamarin/SerilogRepro/iOS/SerilogRepro.iOS.csproj".-- FAILED

Build FAILED.
Errors:

/Users/ghuntley/Dropbox/OSS/repros/xamarin/SerilogRepro/iOS/SerilogRepro.iOS.csproj (Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets (_CompileToNative target) ->

	MTOUCH: error MT2002: Failed to resolve "System.Int32 System.Runtime.InteropServices.Marshal::GetHRForException(System.Exception)" reference from "System.Runtime.InteropServices, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

	 0 Warning(s)
	 1 Error(s)

Time Elapsed 00:00:11.1149520

---------------------- Done ----------------------

Build: 1 error, 0 warnings
Comment 2 Geoffrey Huntley 2016-08-23 06:52:37 UTC
Looks like GetHRForException is not available on iOS:

https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs#L420-L430

Even though the documentation says that it should be:

https://developer.xamarin.com/api/member/System.Runtime.InteropServices.Marshal.GetHRForException/p/System.Exception/

Which is defined at:

https://github.com/mono/mono/blob/master/mcs/class/corlib/Documentation/en/System.Runtime.InteropServices/Marshal.xml

This essentially means consuming .NET assemblies which use:

System.Runtime.InteropServices.Marshal.GetHRForException(exception/int32)

Will not work on Xamarin.iOS.
Comment 3 CraigD 2016-08-24 05:34:30 UTC
Hey Geoffrey, just a note on the documentation - we have a full BCL docset available for reference. A member's presence in the API docs doesn't mean it is necessarily available in our Mac, iOS, and/or Android products. Many other types (like Reflection.Emit) are also documented, but not available in iOS. 

The source, on the other hand, does suggest that method (and a few others in that class) are unavailable in FULL_AOT_RUNTIME.

This cute new site from Microsoft
http://apisof.net/catalog/System.Runtime.InteropServices.Marshal.GetHRForException(Exception)
further confirms that it's available in pretty much everything else -- maybe someone else can fill in the background as to why it's missing from iOS.
Comment 4 Geoffrey Huntley 2016-08-24 09:59:56 UTC
Cheers Craig, it would be good to figure out why Marshal.GetHRForException (this bugzilla issue) is not surfaced in the iOS API but it's inverted cousin Marshall.GetExceptionForHR is. 

Why one and not the other?

For proper context here's the NuGet package I'm consuming:

https://www.nuget.org/packages/serilog.sinks.seq

Here's the source code/line in the assembly which is blowing up:

https://github.com/serilog/serilog-sinks-seq/blob/2299e7b7badc82daf6a4c693a0b16f591b50ac38/src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs#L397-L404
Comment 5 Marek Safar 2016-08-24 10:06:49 UTC
Fixed in C8.
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2016-08-29 17:03:51 UTC
## Status update for any users watching this bug

The fix mentioned in Comment 5 is not yet included in the current Cycle 8 Beta 2 version from August 24.  It will be included in the next Beta version.

In case it might be of interest, it is also already present in the Continuos Builds of Xamarin.iOS (see https://github.com/xamarin/xamarin-macios/wiki).