diff --git a/LibGit2Sharp/Core/FilePathMarshaler.cs b/LibGit2Sharp/Core/FilePathMarshaler.cs index ec239f354..222543725 100644 --- a/LibGit2Sharp/Core/FilePathMarshaler.cs +++ b/LibGit2Sharp/Core/FilePathMarshaler.cs @@ -81,20 +81,29 @@ public IntPtr MarshalManagedToNative(Object managedObj) } var filePath = managedObj as FilePath; + if (null != filePath) + { + return FromManaged(filePath); + } - if (null == filePath) + var expectedType = typeof(FilePath); + var actualType = managedObj.GetType(); + + if (actualType.FullName == expectedType.FullName) { - var expectedType = typeof(FilePath); - var actualType = managedObj.GetType(); - - throw new MarshalDirectiveException( - string.Format(CultureInfo.InvariantCulture, - "FilePathMarshaler must be used on a FilePath. Expected '{0}' from '{1}'; received '{2}' from '{3}'.", - expectedType.FullName, expectedType.Assembly.Location, - actualType.FullName, actualType.Assembly.Location)); + var posixProperty = actualType.GetProperty("Posix"); + if (posixProperty != null && posixProperty.PropertyType == typeof(string)) + { + var reflectedFilePath = (string)posixProperty.GetValue(managedObj, null); + return FromManaged(reflectedFilePath); + } } - return FromManaged(filePath); + throw new MarshalDirectiveException( + string.Format(CultureInfo.InvariantCulture, + "FilePathMarshaler must be used on a FilePath. Expected '{0}' from '{1}'; received '{2}' from '{3}'.", + expectedType.FullName, expectedType.Assembly.Location, + actualType.FullName, actualType.Assembly.Location)); } public Object MarshalNativeToManaged(IntPtr pNativeData) @@ -111,7 +120,12 @@ public static IntPtr FromManaged(FilePath filePath) return IntPtr.Zero; } - return Utf8Marshaler.FromManaged(filePath.Posix); + return FromManaged(filePath.Posix); + } + + private static IntPtr FromManaged(string posixFilePath) + { + return Utf8Marshaler.FromManaged(posixFilePath); } public static FilePath FromNative(IntPtr pNativeData)