2021年3月29日星期一

Any changes to solution yields CefSharp "File Not Found" error

I've been updating a project in git as I make improvements and recently have implemented OAuth2 sign in with Google over the less secure, standard method. I'm using CefSharp to embed the browser window into a windows form. Here's the parent sub called:

    Async Function AuthIt() As Task(Of Boolean)      If Await RunAuth() Then          Return True      Else          Return False      End If  End Function  

And here's the authentication sub:

 Public Async Function RunAuth() As Task(Of Boolean)      Dim state As String = randomDatabase64url(32)      Dim code_verifier As String = randomDatabase64url(32)      Dim code_challenge As String = base64urlencodeNoPadding(sha256(code_verifier))      Dim redirectUri As String = String.Format("http://{0}:{1}/", IPAddress.Loopback, GetRandomUnusedPort())      output("redirect URI: " + redirectUri)      Dim http As HttpListener = New HttpListener()      Dim manager As HttpListenerTimeoutManager = http.TimeoutManager      manager.HeaderWait = TimeSpan.FromMinutes(1)      manager.IdleConnection = TimeSpan.FromMinutes(1)      http.Prefixes.Add(redirectUri)      output("Http redirect is listening...")      http.Start()        Dim authRequest As String = String.Format("{0}?access_type=offline&response_type=code&scope={1}&redirect_uri={2}&login_hint={3}&client_id={4}&state={5}&code_challenge={6}&code_challenge_method={7}",              authEndpoint,              scopes,              Uri.EscapeDataString(redirectUri),              EmailUN,              clientID,              state,              code_challenge,              code_challenge_method)      Dim embeddedBrowser = New ChromiumWebBrowser(authRequest)      EmailFunctions.EmailTable.Controls.Add(embeddedBrowser)      EmailFunctions.Show()        Dim context = Await http.GetContextAsync()      Dim response = context.Response      Dim responseString As String = String.Format("<html><head>SPROCKETS ARE TURNING<br><br></head><body>Signing in and closing this window...</body></html>")      Dim buffer = Encoding.UTF8.GetBytes(responseString)      response.ContentLength64 = buffer.Length      Dim responseOutput = response.OutputStream      Dim responseTask As Task = responseOutput.          WriteAsync(buffer, 0, buffer.Length).          ContinueWith(Sub(task)                           responseOutput.Close()                           http.Stop()                           output("HTTP listener stopped")                           Sleep(500)                       End Sub)      If context.Request.QueryString.Get("error") IsNot Nothing Then          output(String.Format("OAuth authorization error: {0}.", context.Request.QueryString.Get("error")))          Return False      End If      If context.Request.QueryString.Get("code") Is Nothing Then          output("Malformed authorization response. " + context.Request.QueryString.ToString)          Return False      End If      Dim authCode = context.Request.QueryString.Get("code")      Dim incoming_state = context.Request.QueryString.Get("state")      If incoming_state <> state Then          output(String.Format("Received request with invalid state ({0})", incoming_state))          Return False      End If      output("Authorization code: " & authCode)      Sleep(500)      If Not Await performCodeExchange(authCode, code_verifier, redirectUri) Then          Return False      End If      Return True  End Function  

It flags on the following line:

        Dim embeddedBrowser = New ChromiumWebBrowser(authRequest)  

Now here's the weird part. I pushed to my git repo from my work computer. I pulled from my home computer. If I make absolutely no changes I can run the code without issue. If I make literally any changes at all I get the following exception:

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'CefSharp.Core.Runtime, Version=88.2.90.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.
Source=CefSharp.Core StackTrace: at CefSharp.Cef.get_IsInitialized() at CefSharp.WinForms.ChromiumWebBrowser.InitializeFieldsAndCefIfRequired() at CefSharp.WinForms.ChromiumWebBrowser..ctor(String address, IRequestContext requestContext) at Altium_Package_Generator.Authorization.VB$StateMachine_14_RunAuth.MoveNext() in C:\Users\rsmith\source\repos\Altium Package Generator\Altium Package Generator\Altium Package Generator\Modules\GmailOauth2.vb:line 115 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Altium_Package_Generator.Authorization.VB$StateMachine_8_AuthIt.MoveNext() in C:\Users\rsmith\source\repos\Altium Package Generator\Altium Package Generator\Altium Package Generator\Modules\GmailOauth2.vb:line 22 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Altium_Package_Generator.MainWindow.VB$StateMachine_9_EmailButton_Click.MoveNext() in C:\Users\rsmith\source\repos\Altium Package Generator\Altium Package Generator\Altium Package Generator\Forms\Main Window.vb:line 178

The only way to "clear" this error and get it to work again is to force a checkout of the git repo branch again. I have compared the directories before and after the change. No files appear to be different other than whatever change I've made to the solution. I've tried changing what a completely unrelated messagebox says and it will still throw this error. I've tried adding or deleteing an unrelated app setting and it will still throw this error. I've tried uninstalling and reinstalling the CefSharp nuget package as well as deleting my bin and obj folders. Google is no help at this point and I am enough of a noob to not know what the heck is going on. Can somebody please help me? I've been stuck on this for over a week. I'm not looking to use the GoogleWebAuthorizationBroker, as it does not allow you to embed the browser in a form. This method worked flawlessly for over two weeks while I was making other non-OAuth2 related updates.

https://stackoverflow.com/questions/66863864/any-changes-to-solution-yields-cefsharp-file-not-found-error March 30, 2021 at 10:06AM

没有评论:

发表评论