-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How I can fix this issue using this repo with WinForms app? #2
Comments
Hi @zydjohnHotmail
This code run in a .net core application inside a loop with a 30 second interval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello:
I found your repo., it seems to be a good one, so I wanted to give it a try.
For using the console app by following the example from here:
https://github.com/mahdibland/Selenium-Proxy-Authentication.Chrome/blob/main/SeleniumProxyAuthentication.Sample/Program.cs
It works.
However, I want to use this repo in WinForms app. So have done the following:
Create a WinForms app project targeting .NET 6.0 (X64 CPU) on Windows 10 (Version 21H2). My IDE is Visual Studio 2022.
Install NUGET packages:
PM> Install-Package Selenium.Support -Version 4.2.0
PM> Install-Package Selenium.WebDriver -Version 4.2.0
PM> Install-Package Selenium.WebDriver.ChromeDriver -Version 102.0.5005.6102
PM> Install-Package SeleniumProxyAuthentication.Chrome -Version 2.1.1
The following is my C# code trying to do the same as console app.
using OpenQA.Selenium.Chrome;
using SeleniumProxyAuthentication;
namespace SeleniumProxy1Form
{
public partial class Form1 : Form
{
#pragma warning disable CA2211 // Non-constant fields should not be visible
public static ChromeDriver Proxy_Driver;
#pragma warning restore CA2211 // Non-constant fields should not be visible
}
But when I run my program, I always get this kind of error:
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
at Interop.User32.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SeleniumProxy1Form.Program.Main() in C:\Selenium\SeleniumProxy1Form\SeleniumProxy1Form\Program.cs:line 14
This exception was originally thrown at this call stack:
Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions)
Microsoft.Win32.SafeHandles.SafeFileHandle.Open(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.OSFileStreamStrategy.OSFileStreamStrategy(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.FileStreamHelpers.ChooseStrategy(System.IO.FileStream, string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, int, System.IO.FileOptions, long)
System.IO.FileStream.FileStream(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, int, bool)
System.IO.Compression.ZipFileExtensions.DoCreateEntryFromFile(System.IO.Compression.ZipArchive, string, string, System.IO.Compression.CompressionLevel?)
System.IO.Compression.ZipFile.DoCreateFromDirectory(string, string, System.IO.Compression.CompressionLevel?, bool, System.Text.Encoding)
System.IO.Compression.ZipFile.CreateFromDirectory(string, string)
SeleniumProxyAuthentication.Utilities..cctor.AnonymousMethod__9_5(string, string)
...
[Call Stack Truncated]
Inner Exception 1:
IOException: The process cannot access the file 'C:\Users\John\AppData\Roaming\ProxyAuthCache\4.3.1.1796950237348\Details\manifest.json' because it is being used by another process.
By the way, the following C# code works for console app project.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
namespace SeleniumProxyAuthentication.Sample
{
public class Program
{
private static readonly ChromeOptions Chrome_Options = new();
}
I was thinking that my console project is using the json file, but I stop the console project, and change different proxy, or I even reboot my PC. But I still get the same error, but the console app project always works.
Please let me know how I can fix this issue, why it happens only for WinForms app?
Thanks,
The text was updated successfully, but these errors were encountered: