-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New version of NetAnalyzers throws CA1420 for delegates #6094
Comments
dotnet/runtime#63714 has some info around the analyzer. To my understanding, the analyzer should fire only if you have |
I do not believe so. But all the parameters and things are just IntPtr, so that is really the most basic arg type... |
Hi, dotnet new console Replace the content of "Program.cs" with: using System.Runtime.InteropServices;
class Program
{
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
public struct testStruct
{
public CULong testPrp;
}
[UnmanagedFunctionPointerAttribute(CallingConvention.StdCall, CharSet = CharSet.Auto)]
internal delegate CULong fncDlg(ref testStruct strcPrm);
static void Main()
{
var lb = NativeLibrary.Load(@"test.dll");
var fnc = NativeLibrary.GetExport(lb, "testFnc");
testStruct strcObj = new testStruct();
//#pragma warning disable CA1420
var dlg = Marshal.GetDelegateForFunctionPointer<fncDlg>(fnc);
//#pragma warning restore CA1420
dlg(ref strcObj);
NativeLibrary.Free(lb);
}
} and dotnet build show:
dotnet version: 7.0.100-preview.7.22377.5 |
Does it compile with the older nuger package? |
In 6.0.100-rc.2.21505.57, it works fine and doesn't warn. |
Analyzer
Diagnostic ID: CA1420
Delegates with managed types as parameters or the return type require runtime marshalling to be enabled in the assembly where the delegate is defined
Analyzer source
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 7.0.0-preview1.22302.1
Describe the bug
D:\a_work\1\s\src\Controls\src\Core\Platform\Tizen\Extensions\DragDropExtensions.cs(89,28): error CA1420: Delegates with managed types as parameters or the return type require runtime marshalling to be enabled in the assembly where the delegate is defined. [D:\a_work\1\s\src\Controls\src\Core\Controls.Core.csproj]
I started getting this issue after updating the package from:
Steps To Reproduce
dotnet build Microsoft.Maui.BuildTasks.slnf /p:configuration=Release
Expected behavior
Builds.
Actual behavior
Error.
Additional context
You may need to install the tizen workload, but I also saw this on other projects. I know this is a vague issue with a "download my code and build" but I am not sure what this error even means. Is it saying that delegates are not good?
I think it seems to be if some p/invoke has a delegate that uses a IntPtr
The text was updated successfully, but these errors were encountered: