0

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>
  • 1
    Put a break point in c# where code enters dll. The step into the dll with F11. Then add break point and see if code stops. – jdweng Aug 31 '20 at 06:42
  • @jdweng I am new to c# so I am not sure if what I did is right. What I did is: The first function called in dll is "GetPluginInfo()". I put a breakpoint at the function brace. Then I tried starting debugging. Still my external app is not loading. On the other hand, i tried to add breakpoint from the second window (the one that had attach option) from Debug->new breakpoint->function breakpoint. It worked. – Ansar Bedharudeen Aug 31 '20 at 07:00
  • another thing that confuses me is why do I have to attach an external program if I have already mentioned External Program in VS project properties's debug options. I think the issue starts here. – Ansar Bedharudeen Aug 31 '20 at 07:29
  • I do not know the answer. It probably has to do with loading the debug data from the pdb file. I suspect not all the debug info automatically gets loaded to save memory. A project sln file has more than one section and only main section get loaded. See : https://learn.microsoft.com/en-us/visualstudio/extensibility/internals/solution-dot-sln-file?view=vs-2019 – jdweng Aug 31 '20 at 08:18

1 Answers1

0

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:

enter image description here

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.

enter image description here

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • thanks! it worked :) . But now I ran into another issue. Could not load file or assembly “System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51”. I have installed System.Text.Json through nuget. My code works when I run it through a console project. But when I compile into dll an use it in amibroker, aforementioned error occurs. Could you point me to the right direction? – Ansar Bedharudeen Sep 01 '20 at 13:26
  • What version of `System.Text.Json` did you install and could you please share the whole error with us? – Mr Qian Sep 01 '20 at 13:29
  • One suggestion, try to add the bindredirect under `app.config` file: ` ` – Mr Qian Sep 01 '20 at 13:42
  • Installed version is 4.7.1. I did mention the following in my app.config file: This too didnt help. – Ansar Bedharudeen Sep 01 '20 at 13:48
  • I have now added the complete error to my question. Also added packages.config entries. – Ansar Bedharudeen Sep 01 '20 at 13:50
  • Please target your project to `Debug/x64` then run `update-package -reinstall` under `Tools`-->`Nuget Package Manager`-->`Package Manager Console`. then delete bin and obj folder, readd the bindredirect in `app.config` file. – Mr Qian Sep 01 '20 at 14:40
  • Besides, you could try to change target framwork version `net472` and then run `update-package -reinstall`. – Mr Qian Sep 01 '20 at 15:07
  • i am developing plugin for x86 app. So can I target my project to Debug/x86? – Ansar Bedharudeen Sep 01 '20 at 15:09
  • Sorry, didnt work... this is the full error, 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. – Ansar Bedharudeen Sep 01 '20 at 15:29
  • === Pre-bind state information === 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 – Ansar Bedharudeen Sep 01 '20 at 15:30
  • Calling assembly : (Unknown). 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: The same bind was seen before, and was failed with hr = 0x80070002. – Ansar Bedharudeen Sep 01 '20 at 15:30
  • Could you please share a small,reproducible sample with us by github or onedrive? Since the issue is complex and the issue may exist under your code, project structure and so on. – Mr Qian Sep 02 '20 at 10:00
  • I don't know if it works : install Newtonsoft.Json nuget package and try. – Mr Qian Sep 02 '20 at 10:04
  • Thanks... I am developing a dll for amibroker. When I test my code as a console app it runs well. I am not sure if you have amibroker installed to check it. I have a doubt. When i build my dll, in my debug folder I have my plugin along with its pdb file and all the refeerence dll's. As per amibroker I am supposed to copy my plugin.dll to amibroker's "plugin" folder. What about my reference dlls? Do I just leave it in debug folder or should I copy it elsewhere? Another thing i noticed is my system.buffers in packages/ref folder is under net45 but I am using 4.6.1. I have redirectbinding though – Ansar Bedharudeen Sep 02 '20 at 12:42
  • Another thing I noticed is each of the reference dll's having "Could not load file or assembly.." error has a dll and an xml file with its name in debug folder. If it helps... – Ansar Bedharudeen Sep 02 '20 at 13:14
  • I tried copying each dll from my bin directory to exe's base directory. One by one error started to go away until came System.Buffers. Here there was a mismatch in assembly version. I did mention a bindingRedirect for system.buffers but still error popped up. A privatePath location was also mentioned to avoid cluttering of exe's base folder, that too was ignored. I think app.config is ignored completely... Is it possible? Could it be some setting that is ignoring app.config? Please advice. I have included my app.config in my Question for your reference. – Ansar Bedharudeen Sep 02 '20 at 15:39