Skip to content

Commit f3d2b0b

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

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

LibGit2Sharp/Core/FilePathMarshaler.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ 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+
var reflectedFilePath = (string)posixProperty.GetValue(managedObj, null);
98+
return FromManaged(reflectedFilePath);
99+
}
100+
}
101+
92102
throw new MarshalDirectiveException(
93103
string.Format(CultureInfo.InvariantCulture,
94104
"FilePathMarshaler must be used on a FilePath. Expected '{0}' from '{1}'; received '{2}' from '{3}'.",
@@ -110,7 +120,12 @@ public static IntPtr FromManaged(FilePath filePath)
110120
return IntPtr.Zero;
111121
}
112122

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

116131
public static FilePath FromNative(IntPtr pNativeData)

0 commit comments

Comments
 (0)