I am using .NET 8 Preview 6 and Visual Studio 2022, updated today.
I updated a library today, changing from DllImport
to LibraryImport
, but it indicates CS0755
.
Here is my imported method declaration:
public unsafe static partial class CppCoreFuncs
{
#region private
[LibraryImport(DLL, EntryPoint = "Poly2Cofs_multi_buf"), SuppressUnmanagedCodeSecurity]
private static partial FuncResult Poly2CofsMultiBuf(void* buffer, InputMode mode);
#endrgion
...
}
This generates the following code:
public unsafe static partial class CppCoreFuncs
{
[System.Runtime.InteropServices.DllImportAttribute("CPP Core.dll", EntryPoint = "Poly2Cofs_multi_buf", ExactSpelling = true)]
private static extern partial global::RWT.ROCT.Core.Public.FuncResult Poly2CofsMultiBuf(void* buffer, global::RWT.ROCT.Core.Public.InputMode mode);
}
When I compile, I get this:
Error CS0755 Both partial method declarations must be extension methods or neither may be an extension method... Core\Microsoft.Interop.LibraryImportGenerator\Microsoft.Interop.LibraryImportGenerator\LibraryImports.g.cs
Documentation: Source generation for platform invokes.
There is no extension method. If I change back to DLLImport
then the next method import declaration with LibraryImport
gets this error. It only appears once.
EDIT
For reference, here is a working code generator produced stub for GeneratedRegexAttribute
:
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "8.0.8.32907")]
internal static partial global::System.Text.RegularExpressions.Regex QuotedOrUnquotedNewLineRx() => global::System.Text.RegularExpressions.Generated.QuotedOrUnquotedNewLineRx_7.Instance;