2

Pulling my hair out here. All was working fine, and then out of the blue, I started to get some errors around Microsoft.Owin.Security. Following some tips on this site, I un-installed that package and all the ones that depended on it (there were a lot) and then re-installed them all.

Now when I run the site in debug, I get this:

An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.

What's frustrating is that nowhere in the stack trace is there anything that I can make any sense of. I'll paste it all below.

.NET 4.7.1 Web Application in Visual Studio 2017

Any tips on how to troubleshoot would be helpful. I've already deleted the entire solution and re-pulled it from TFS. Teammates using the same source code are not seeing this.

EDIT:

The only place I am able to hit a breakpoint is on the constructor in the index controller. That constructor is empty. The breakpoint hits, and then even if I step in debug, the next thing that happens is the error is thrown. It would be nice if I could nail down exactly where/what is causing the error, but I'm having trouble even with that.

Stack Trace: 


[InvalidOperationException: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.]
   System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request) +335995
   System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) +99
   System.Net.Http.HttpClient.GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken) +65
   Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__8.MoveNext() +196

[IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'.]
   Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__8.MoveNext() +662
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.IdentityModel.Protocols.OpenIdConnect.<GetAsync>d__3.MoveNext() +291
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
   Microsoft.IdentityModel.Protocols.<GetConfigurationAsync>d__24.MoveNext() +1129

[InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'.]
   Microsoft.IdentityModel.Protocols.<GetConfigurationAsync>d__24.MoveNext() +1586
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.OpenIdConnect.<ApplyResponseChallengeAsync>d__8.MoveNext() +432
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<ApplyResponseCoreAsync>d__40.MoveNext() +272
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<ApplyResponseAsync>d__39.MoveNext() +271
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<TeardownAsync>d__34.MoveNext() +158
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<Invoke>d__5.MoveNext() +659
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__7.MoveNext() +179
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<Invoke>d__5.MoveNext() +519
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Security.Infrastructure.<Invoke>d__5.MoveNext() +519
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__7.MoveNext() +179
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__12.MoveNext() +180
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159
Casey Crookston
  • 13,016
  • 24
  • 107
  • 193
  • 2
    include the code that uses the HttpClient – Matt.G Mar 22 '19 at 18:42
  • 1
    There are ways to debug that but it's a bit long to explain like that... Anyway, start by disabling "just my code" in Visual Studio (https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2017) then bring the "Exception settings" panel (Debug -> Windows -> Exception Settings) and check "Common Language Runtime Exceptions". Then start your application with the debugger attached, and run it until it breaks on the "An invalid request URI was provided" exception. – Kevin Gosse Mar 22 '19 at 18:46
  • https://github.com/IdentityServer/IdentityServer4/issues/2337 looks similar to this. – John Boker Mar 22 '19 at 18:46
  • From there, open the "callstack" panel, double click on the line that contains "PrepareRequestMessage", then in the "Watch" panel (or open the quickwatch window with shift + f9) type "request". Hopefully the request will still be on the stack, in which case you will be able to inspect it to understand what is this invalid uri – Kevin Gosse Mar 22 '19 at 18:51
  • @Matt.G -- that's part of the problem. I've put breakpoints at every place that uses it, but the error happens before they get hit. – Casey Crookston Mar 22 '19 at 18:51
  • @KevinGosse, followed your steps. Still nothing. Running in debug mode pops the browser which loads with the error, but unline most uncaught runtime errors, VS never stops and shows me where the error is. – Casey Crookston Mar 22 '19 at 19:11
  • try setting `ShowPII = true` in `Configure` method in `Startup` class like `Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;`. This should log additional detail in case of exceptions. Also, could you include the Startup class in the post? – Matt.G Mar 22 '19 at 20:08

3 Answers3

2

In order to log additional details of PII related exceptions, try setting ShowPII = true in Configure method in Startup class like

Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;

This should log additional details to the output window.

Matt.G
  • 3,586
  • 2
  • 10
  • 23
2

I spend two days on this. The problem was incorrect Authority URL. Check the Authority URL you have set in Azure and your application if is the same.

Hope this help someone.

user2693802
  • 136
  • 1
  • 8
1

Please check this thread, and this thread. I believe you need to take care of the "Unable to obtain configuration from" exception, hope these'll help. :)

  • You could be on to something, but even after reading those two threads, I'm still not sure what steps to take. I can't even figure out where this error is originating from. I'm going to make a small edit to the OP – Casey Crookston Mar 22 '19 at 19:03
  • From the second link, I think this comment is useful here: "The application read the OpenId Configuration url from web.config which is composed of the Authority tag and TenantId/TenantName " The problem is definately coming from OWIN (this is a middleware), it might be worth checking how you configure this service apart from these configurations, if these still do not solve the issue! – Péter Kuti Mar 22 '19 at 19:11