VirusTotal .NET API: sample crashed because disposed Objects

177 Views Asked by At

i try to reproduce this code from genbox: https://github.com/Genbox/VirusTotalNet/blob/master/src/VirusTotalNet.Examples/Program.cs

In Line 31: if i try it with the True-Branch, it works fine. But if i try it with a unknown value, the False-Branch in Lin 35 will be accessed.

And then: line 37: .NET-Application crashed because "System.ObjectDisposedException: You cannot access on a disposed object" - Objectname:"System.Net.Http.MultipartFormDataContent"."

With no command, i dispose a object. Is the Problem in threading so i do not have any object for using?

Whats my Failure?

Thanks

Code: My failure seems to be in the line: ScanResult fileResult = await virusTotal.ScanFileAsync(eicar, "Testfile");

private static async Task Main(string[] args)
{
            VirusTotal virusTotal = new VirusTotal("b5509ad49ff184cbe39...baa24a4...5ae8dd015");

            //Use HTTPS instead of HTTP
            virusTotal.UseTLS = true;

            //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
            byte[] eicar = Encoding.ASCII.GetBytes(@"555X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");
            //FileInfo fileInfo = new FileInfo(@"C:\tmp\pngegg.png");

            //Check if the file has been scanned before.
            //VirusTotalNet.Results.FileReport fileReport = await virusTotal.GetFileReportAsync(fileInfo);
            VirusTotalNet.Results.FileReport fileReport = await virusTotal.GetFileReportAsync(eicar);

            bool hasFileBeenScannedBefore = fileReport.ResponseCode == FileReportResponseCode.Present;

            Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));

            //If the file has been scanned before, the results are embedded inside the report.
            if (hasFileBeenScannedBefore)
            {
                PrintScan(fileReport);
            }
            else
            {
                //ScanResult fileResult = await virusTotal.ScanFileAsync(fileInfo);
                ScanResult fileResult = await virusTotal.ScanFileAsync(eicar, "Testfile");
                PrintScan(fileResult);
            }

            Console.WriteLine();

            string scanUrl = "http://www.google.com/";

            UrlReport urlReport = await virusTotal.GetUrlReportAsync(scanUrl);

            bool hasUrlBeenScannedBefore = urlReport.ResponseCode == UrlReportResponseCode.Present;
            Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

            //If the url has been scanned before, the results are embedded inside the report.
            if (hasUrlBeenScannedBefore)
            {
                PrintScan(urlReport);
            }
            else
            {
                UrlScanResult urlResult = await virusTotal.ScanUrlAsync(scanUrl);
                PrintScan(urlResult);
            }
}
0

There are 0 best solutions below