简体   繁体   中英

Unable to debug c# dll project with an external app in Visual Studio 2019 Community edition 16.7.2

This project is an "amibroker plugin" developed in C# using kriasoft's amibroker .NET SDK .

I have "build" my plugin and it works fine when I test it in a "Console project". But when I try to debug it with external app (Amibroker.exe) visual studio abruptly closes down and in a few seconds launches a blank visual studio window with an option to "attach" in place of where we usually see "start" for running our project.

I clicked on the attach option and attached to my amibroker application and it successfully displayed "Debug.Writeline()" messages. But none of my breakpoints are hit. My code is not visible in any window either as it would be normally when I was debugging console app.

Upon research in google, i found out that the external application is supposed to be automatically launched by visual studio and should nave stopped at my breakpoint. This is not happening in my case. I have searched a lot and even updated entire vs2019, yet no progress.

It would be great if anybody could help me out.

Note: "Start without Debugging" works fine.

New Information regarding "Could not load file or assembly 'System.Text.Json": Could not load file or assembly 'System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

Err:510 LOG: DisplayName = System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 (Fully-specified) LOG: Appbase = file:///C:/Program Files (x86)/AmiBroker_New_6.0/ LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). Err:510 LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file: LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\config\\machine.config. LOG: Post-policy reference: System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 LOG: Attempting download of new URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json.DLL. LOG: Attempting download of new URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json/System.Text.Json.DLL. LOG: Attempting download of new URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json.EXE. LOG: Attempting download of new URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json/System.Text.Json.EXE.

My packages.config entries:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CsvTextFieldParser" version="1.2.1" targetFramework="net461" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net461" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
  <package id="System.Memory" version="4.5.4" targetFramework="net461" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
  <package id="System.Text.Encodings.Web" version="4.7.1" targetFramework="net461" />
  <package id="System.Text.Json" version="4.7.1" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
  <package id="UnmanagedExports" version="1.2.7" targetFramework="net461" />
</packages>

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="ghyiouys\;Plugins\;plugins;"/>
            <dependentAssembly>
                <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
                <codeBase version="4.0.1.1" href="Plugins/System.Text.Json.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
                <codeBase version="4.1.4.0" href="Plugins/System.Numerics.Vectors.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Unable to debug c# dll project with an external app in Visual Studio 2019 Community edition 16.7.2

If you just want to step into the breakpoint just with the external program under the debug process through one VS, it cannot be done since VS cannot load the pdb files through the external program. And Start without Debugging will not loads the pdb file so that it works well.

As a suggestion ,

You must additionally start a new vs instance to debug the project through attach to process at the same time.

Using the second suggestion will realize it.

1) First , you should check your extra program:

在此处输入图片说明

The start external program is the full path of your Amibroker.exe and the Command line arguments contains the name of your current project amibroker plugin in VS.

Then , uncheck the option Enable Just My Code under Tools --> Options --> Debugging --> General .

2) Second , remember to add Debugger.Launch(); under the Main function in your cs file like this:

 static void Main(string[] args)
        {
            Debugger.Launch();

            //add any code here

        }

3) Third , click Start Debugging and then open Debug --> Windows --> Modules and then search any dlls about Amibroker and then right-click on them--> Always Load Automatically .

4) Fourth , stop Debug process and then delete bin and obj folder. After that, click Start Debugging again, wait for a moment, and you can see the window about Choose the Just-In-Time Debugger window. You should select VS2019 IDE and it starts a new vs instance with the current project by attach into process . And with it, you can step into the breakpoint to debug the code.

在此处输入图片说明

Or you could try my second suggestion to start the process automatically.

Note : the second suggestion will create a new VS Instance by Attach to Process with your amibroker plugin project at the same time.

===========================================

Besides , if you still face the same issue, please try to disable any third party extensions under Extensions menu--> Manage Extensions to check if there is something causing it.

Also , Reset All VS settings by Tools --> Options --> Import and Export Settings --> Reset All Settings and then disable the option Enable Just My Code option .

Also , there is a similar issue about it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM