WhiteFalcon
WhiteFalcon
CC#
Created by WhiteFalcon on 9/18/2024 in #help
Sharing the custom marshalled type across libraries
that would restrict me from using the managed types aswell as making the function static, right? thank you for the suggestion, i'll do that
6 replies
CC#
Created by WhiteFalcon on 9/18/2024 in #help
Sharing the custom marshalled type across libraries
I guess the solution was to disable runtime marshalling with [assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling] The issue with such solution for me was that it triggers CA1420: Property, type, or attribute requires runtime marshalling for delegates marked with [UnmanagedFunctionPointer(CallingConvention.Cdecl)] or any use of Marshal.GetFunctionPointerForDelegate with delegates managed types (even if they have NativeMarshaller)
6 replies
CC#
Created by WhiteFalcon on 9/18/2024 in #help
Sharing the custom marshalled type across libraries
The error still persists if i removed the NativeMarshalling attribute and manually added MarshalUsing to each argument/return
C#
using CustomMarshalling;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace CustomMarshalling2
{
internal partial class NativeLib2
{
private const string LibName = "nativelib2";

[LibraryImport(LibName)]
internal static partial void PrintErrorData([MarshalUsing(typeof(ErrorDataMarshaller))] ErrorData errorData);

[LibraryImport(LibName)]
[return: MarshalUsing(typeof(ErrorDataMarshaller))]
internal static partial ErrorData GetFatalErrorIfNegative(int code);
}
}
C#
using CustomMarshalling;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace CustomMarshalling2
{
internal partial class NativeLib2
{
private const string LibName = "nativelib2";

[LibraryImport(LibName)]
internal static partial void PrintErrorData([MarshalUsing(typeof(ErrorDataMarshaller))] ErrorData errorData);

[LibraryImport(LibName)]
[return: MarshalUsing(typeof(ErrorDataMarshaller))]
internal static partial ErrorData GetFatalErrorIfNegative(int code);
}
}
6 replies
CC#
Created by WhiteFalcon on 9/18/2024 in #help
Sharing the custom marshalled type across libraries
TLDR:
1) Library A defines publicly ErrorData and custom marshallers
2) Library A imports native library and uses the ErrorData as arguments/return type, everything compiles fine so far
3) Library B links against A
4) Library B imports another native library(or same) that also uses ErrorData; SYSLIB1051 error is generated
1) Library A defines publicly ErrorData and custom marshallers
2) Library A imports native library and uses the ErrorData as arguments/return type, everything compiles fine so far
3) Library B links against A
4) Library B imports another native library(or same) that also uses ErrorData; SYSLIB1051 error is generated
6 replies