0

I have an ADK provided by a hardware manufacturer for connecting to and using their hardware.

The ADK is a DLL we have referenced in our project, then called and used methods based on events. The problem is that the DLL constantly writes some text to the console. The string is always the same, We need to use the console so completely turning it off is not a viable solution.

I have attempted an implementation of the TextWriter class that ignores this string but this output from the DLL does not come into the class when I breakpoint inside it.

The TextWriter we built looked like this;

public class MyTextWriter : TextWriter
{
    private TextWriter _standardOut;
    public MyTextWriter(TextWriter ConsoleOut)
    {
        this._standardOut = ConsoleOut;
    }
    public override Encoding Encoding
    {
        get
        {
            return Encoding.ASCII;
        }
    }
    public override void WriteLine(string val)
    {
        if(val != "Hello")
        {
            _standardOut.WriteLine(val);
        }
    }
}

Is there any other way to stop this DLL writing to the console?

eocron
  • 6,885
  • 1
  • 21
  • 50
Sumped
  • 46
  • 10
  • 1
    Have you tried complaining to the dll developer? – Neil Mar 20 '19 at 16:20
  • 1
    Check this [possibly duplicate question](https://stackoverflow.com/questions/6024172/is-it-possible-to-intercept-console-output). You have to tell the Console to use your writer with `Console.SetOut(myWriter)`. This may not work if the DLL uses the Win32 API directly though – Panagiotis Kanavos Mar 20 '19 at 16:21
  • I'd say that printing `Hello` to the console all the time is a valid reason to contact the vendor - production code that does this may display other ... idiosyncratic behaviour. It may mean that debug code was included in the production DLL when it shouldn't. – Panagiotis Kanavos Mar 20 '19 at 16:23
  • On the other hand, if the DLL uses .NET's tracing infrastructure and *your* configuration writes all debug or information messages to the console, you can turn it off yourself by changing the tracing configuration. – Panagiotis Kanavos Mar 20 '19 at 16:25
  • I did use the Console.Setout with my example code sorry for not making that clear, The string isn't hello it's just an example placeholder. we have tried to reach out to the manufacturer but no luck as yet. – Sumped Mar 20 '19 at 16:26

0 Answers0