[fix] fix raising NullReferenceException in generating MethodBridge for MonoPInvokeCallbackAttribute while constructor arguments is empty.

main
walon 2025-10-14 17:13:28 +08:00
parent 01754c8fb4
commit 391cd04cdf
1 changed files with 6 additions and 1 deletions

View File

@ -559,6 +559,11 @@ namespace HybridCLR.Editor.MethodBridge
{
return CallingConvention.Winapi;
}
if (monoPInvokeCallbackAttr.ConstructorArguments.Count == 0)
{
Debug.LogError($"MonoPInvokeCallbackAttribute on method {method.FullName} has no constructor arguments. Using CallingConvention.Winapi as default.");
return CallingConvention.Winapi;
}
object delegateTypeSig = monoPInvokeCallbackAttr.ConstructorArguments[0].Value;
TypeDef delegateTypeDef;
@ -580,7 +585,7 @@ namespace HybridCLR.Editor.MethodBridge
throw new NotSupportedException($"Unsupported delegate type: {delegateTypeSig}");
}
var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute");
if (attr == null)
if (attr == null || attr.ConstructorArguments.Count == 0)
{
return CallingConvention.Winapi;
}