Skip to content

Commit c33a348

Browse files
committed
Use reflection to work around CustomMarshaler bug
Fixes libgit2#241
1 parent 85846c4 commit c33a348

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

LibGit2Sharp/Core/FilePathMarshaler.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public IntPtr MarshalManagedToNative(Object managedObj)
8989
var expectedType = typeof(FilePath);
9090
var actualType = managedObj.GetType();
9191

92+
if (actualType.FullName == expectedType.FullName)
93+
{
94+
var posixProperty = actualType.GetProperty("Posix");
95+
if (posixProperty != null && posixProperty.PropertyType == typeof(string))
96+
{
97+
return FromManaged((string)posixProperty.GetValue(managedObj, null));
98+
}
99+
}
100+
92101
throw new MarshalDirectiveException(
93102
string.Format(CultureInfo.InvariantCulture,
94103
"FilePathMarshaler must be used on a FilePath. Expected '{0}' from '{1}'; received '{2}' from '{3}'.",
@@ -110,7 +119,12 @@ public static IntPtr FromManaged(FilePath filePath)
110119
return IntPtr.Zero;
111120
}
112121

113-
return Utf8Marshaler.FromManaged(filePath.Posix);
122+
return FromManaged(filePath.Posix);
123+
}
124+
125+
private static IntPtr FromManaged(string posixFilePath)
126+
{
127+
return Utf8Marshaler.FromManaged(posixFilePath);
114128
}
115129

116130
public static FilePath FromNative(IntPtr pNativeData)

0 commit comments

Comments
 (0)