admin管理员组

文章数量:1321805

I'm using a .NET 8 DLL from which a function AddOne is exported:

[UnmanagedCallersOnly(EntryPoint ="AddOne")]
public static int AddOne(int x)
{
    Console.WriteLine("Inside AddOne");
    return x + 1;
}

Then I build the DLL using this command:

dotnet publish -f net8.0 -c Debug -r win-x64 -p:PublishAot=true -p:NativeLib=Shared -p:SelfContained=true

I copy the .pdb and .dll file from the path ClassLibrary\bin\Debug\net8.0\win-x64\native into the path of my host application.

The host application is a .NET framework console application. I consume the dll with this code:

[DllImport("ClassLibrary.dll")]
private static extern int AddOne(int x);

But when I try to debug into the dll, my breakpoint on the line Console.WriteLine("Inside AddOne"); is never hit.

What am I doing wrong?

Full source code is in this commit:

I'm using a .NET 8 DLL from which a function AddOne is exported:

[UnmanagedCallersOnly(EntryPoint ="AddOne")]
public static int AddOne(int x)
{
    Console.WriteLine("Inside AddOne");
    return x + 1;
}

Then I build the DLL using this command:

dotnet publish -f net8.0 -c Debug -r win-x64 -p:PublishAot=true -p:NativeLib=Shared -p:SelfContained=true

I copy the .pdb and .dll file from the path ClassLibrary\bin\Debug\net8.0\win-x64\native into the path of my host application.

The host application is a .NET framework console application. I consume the dll with this code:

[DllImport("ClassLibrary.dll")]
private static extern int AddOne(int x);

But when I try to debug into the dll, my breakpoint on the line Console.WriteLine("Inside AddOne"); is never hit.

What am I doing wrong?

Full source code is in this commit: https://github/JYPDWhite/DllExportTest/commit/6868cc1cece734e7645ffba061eed915a79dd3c3

Share Improve this question edited Jan 15 at 17:39 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Jan 15 at 16:12 WhiteWhite 3591 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Enable mixed-mode debugging:

If you're using .NET Framework code, which has no debug launch profile, follow these steps:

  1. Right-click the project in solution explorer and select Properties

  2. On the left menu, select Debug.

  3. In the Debugger engines section, select the Enable native code debugging property

  4. To apply the property change, close the Properties pane.

本文标签: cDebugging a DLL with exported functions using UnmanagedCallersOnlyStack Overflow