Acquire access token from Azure AD using username and password for Azure DevOps REST Api - azure-devops

We are implementing AD registered application (deployed as Azure App Service) to access Azure DevOps Rest Api, I have followed the authentication guidance provided for Azure DevOps and using authentication context acquire access token by sending username and password. Although MS is not recommending this authentication process, the reason we are doing this is the user account has permissions to specific access on multiple projects in different organizations. This way we obtain token for that user and access Azure DevOps REST Api's accessible to the user. Basically we created a generic user account that can access DevOps REST Api's from my application.
In the local environment, I am able to get the access token for the user using below code,
AuthenticationContext ctx = new AuthenticationContext("https://login.microsoftonline.com/org.onmicrosoft.com/");
AuthenticationResult result = null;
var username = "********"; // This is your AAD username in the form user#domain.com.
var password = "********"; // This is your AAD password.
var adalCredential = new UserPasswordCredential(username, password);
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
try
{
result = ctx.AcquireTokenAsync(azureDevOpsResourceId, clientId, adalCredential).Result;
Console.WriteLine("Token expires on: " + result.ExpiresOn);
}
catch (Exception ex)
{
Console.WriteLine("{0}: {1}", ex.GetType(), ex.Message);
}
The same code while accessing through the web application is not working as expected, and throws below ADAL Exception,
System.AggregateException: One or more errors occurred. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: parsing_wstrust_response_failed: Parsing WS-Trust response failed
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.WsTrust.WsTrustResponse.CreateFromResponseDocument(XDocument responseDocument, WsTrustVersion version)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.WsTrust.WsTrustRequest.<SendRequestAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenNonInteractiveHandler.<PreTokenRequestAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.<RunAsync>d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions.<AcquireTokenAsync>d__0.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
Why is this error, parsing_wstrust_response_failed is occurring when run from the application? I also wanted to know is the approach we are following is correct? do we have an alternate solution that can be implemented to achieve what we are looking for?

Honestly, this code looks fine. However, from the error message, it seems that no successful response has been received.
I create a test web app with your code to get a token. My environment: .NET framework 4.7.2 and ADAL 5.2.7. The result is that I can successfully get a token.
So, you may try to update to use latest ADAL version and deploy you web application to a new web app.
If the problem still occurs, you may try to directly make a http request to get a token:
POST https://login.microsoftonline.com/{tenant-id}/oauth2/token
Content-Type: application/x-www-form-urlencoded
grant_type=password
&resource={resource}
&username={username}
&password={password}
&client_id={client-id}

Related

Cosmos DB EF ReadItemAsync exception occurs Response status code does not indicate success: Unauthorized (401);

The command I'm executing:
var feature = await container.ReadItemAsync<CosmosNormalizedFeatureModel>(guid, new Microsoft.Azure.Cosmos.PartitionKey(partitionKey));
Throws an exception:
Response status code does not indicate success: Unauthorized (401); Substatus: 0; ActivityId: ; Reason: ();
I don't believe this is true, but I don't see anything wrong either.
when I use GetItemLinqQueryable I have no issues connecting to Cosmos
I've verified the partition key exists + set to correct property and returns data
I've verified the guid/id exists and returns data
I've verified the container is set to the correct container
Microsoft.Azure.Cosmos 3.20.1
Not sure what else I can check to troubleshoot the issue. Thanks!
Stack trace
at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage[T](ResponseMessage responseMessage, Func`2 createResponse)
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.CreateItemResponse[T](ResponseMessage responseMessage)
at Microsoft.Azure.Cosmos.ContainerCore.<ReadItemAsync>d__56`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.Cosmos.ClientContextCore.<RunWithDiagnosticsHelperAsync>d__38`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Azure.Cosmos.ClientContextCore.<OperationHelperWithRootTraceAsync>d__29`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at xxx.<GetFeatureByGuid>d__7.MoveNext() in D:\xxx.cs:line 183
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at xxx.<GetNormalizedILIReportFeatureByGuid>d__10.MoveNext() in D:\xxx.cs:line 280
Based on comments - you are using Bulk mode.
When using Bulk mode, operations are packed together to improve network performance (the operation type is not relevant, read operations can be packed with write operations) and sent as a single payload to the backend.
The payload is of a different type calling a different API (so the backend can unpack them and process them and return a packed response).
This API uses the Write keys (because inside the package there could be any type of operation). The fact that you are using the Read-only keys is what is causing the 401. Ideally the backend should be more explicit in the error it returns though.
The key being used to connect to cosmos is a read key, it appears that the point read requires a read/write key.

New client not accepted

please could you help with following mysterious & interesting issue?
IIS websites:
IdentityServer (v 2.0.1) - used to login & get clientToken for service account (which is furhter used for IdentityServerApi calls)
IdentityServerApi - used to get user data from DB
WebSite1
WebSite2
WebSite3
WebSite4
NewWebapp
Startup.cs in IdentityServer contains Clients for all web sites
NewWebapp was added recently with exact same configuration as other websites (only ReturnUrl differs)
Classic (functional) scenario is:
WebApp gets clientToken from IdentityServer and this is used for all requests to IdentityServerApi (containing user & other data).
Current behavior is:
All WebSites1-4 work correctly. But when NewWebapp is trying to get clientToken it gets following error:
Exception:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at mySupply_project.Utils.RemoteUserApiProvider.<CallUserApi>d__7.MoveNext() in C:\tfs43\MySupply\MySupply-project-multilingual\mySupply-project\Utils\RemoteUserApiProvider.cs:line 91 InnerException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. Message: Exception StackTrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at mySupply_project.Utils.RemoteUserApiProvider.d__7.MoveNext() in C:\tfs43\MySupply\MySupply-project-multilingual\mySupply-project\Utils\RemoteUserApiProvider.cs:line 91
TraceLog of IdentityServer does not contain any useful information.
When testing in Postman, requests are processed well, clientToken & data are correctly returned in all cases (including NewWebapp).
Please, does anyone have idea what could be possibly wrong?
Thanks a lot!
Update:
RemoteUserApiProvider calls this method:
public async Task<string> CallUserApi(string url)
{
var accesToken = ClientToken();
if (string.IsNullOrEmpty(accesToken))
return string.Empty;
try
{
using (var client = new HttpClient())
{
client.SetBearerToken(accesToken);
// turn off validation of a certificate for testing
CheckCertificationSettings();
_logger.LogInfo($"[CallUserApi] Url: {url}");
var result = await client.GetStringAsync(url);
return result;
}
}
catch (Exception ex)
{
_logger.LogException(ex, Source.IdentityServer);
return string.Empty;
}
}
This method CallUserApi calls url of IdentityServerApi (via https).
To get clientToken, IdentityServer (not Api) is called via https.
This doesn't seem to be identity related issue, what URL does the RemoteUserApiProbider call into? Check if the SSL of the URL is trusted on the same box as where the new client app is being hosted. You can use powershell or browser
Updated:
And try go through this checklist to see if any one of those is matched

get_Error_BPAAsimovNotReachedRetrying() not found when creating/validating cluster

I'm trying to create a standalone Service Fabric cluster using 5.4.145.9494 SDK bits and when running .\TestConfiguration.ps1 .\ClusterConfig.Unsecure.DevCluster.json with no changes to the downloaded SDK whatsoever I'm getting following error:
Test Config failed with exception: System.AggregateException: One or
more errors occurred. ---> System.MissingMethodExce ption: Method not
found: 'System.String
System.Fabric.Strings.StringResources.get_Error_BPAAsimovNotReachedRetrying()'.
at
Microsoft.ServiceFabric.DeploymentManager.Common.StandaloneSettingsValidator.Validate()
at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.IsJsonConfigModelValid(StandAloneInstallerJson
Model config) at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.AnalyzeClusterSetup(String
configPath, String cabPath, Boolean usingClusterManifest,
FabricPackageType fabricPackageType) at
System.Threading.Tasks.Task`1.InnerInvoke() at
System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.d__3.MoveNext()
--- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification) at
Microsoft.ServiceFabric.DeploymentManager.DeploymentManagerInternal.BpaAnalyzeClusterSetup(String
clusterConfigPat h, String fabricPackagePath) at
Microsoft.ServiceFabric.Powershell.ClusterCmdletBase.TestConfig(String
clusterConfigPath, String fabricPackagePath ) at
System.Management.Automation.CommandProcessor.ProcessRecord()
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'System.String System.Fabric.Strings.StringRe
sources.get_Error_BPAAsimovNotReachedRetrying()'. at
Microsoft.ServiceFabric.DeploymentManager.Common.StandaloneSettingsValidator.Validate()
at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.IsJsonConfigModelValid(StandAloneInstallerJson
Model config) at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.AnalyzeClusterSetup(String
configPath, String cabPath, Boolean usingClusterManifest,
FabricPackageType fabricPackageType) at
System.Threading.Tasks.Task`1.InnerInvoke() at
System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.ServiceFabric.DeploymentManager.BPA.BestPracticesAnalyzer.d__3.MoveNext()<---
The same error is printed when trying to use createservicefabriccluster.ps1.
I'm trying it on a Windows Server 2012R2 machine. Interestingly, the same works just fine on another Windows 10 machine. There are other differences (Windows Server 2012 R2 machine is in secure environment with a bunch of access policies around network, disk access, etc.) but it's hard to tell what's actually causing validation to fail with a message like that ...
My question: How do I get pass that "MissingMethodException" noise and learn the real issue?
Turns out that's the exception you get when the machine is already part of a previously defined standalone, non-Dev cluster. Running .\cleanFabric.ps1 made it work again.
Somebody should make the error message better ...

Any idea why Facebook Provider fails in the below code?

I implemented OAUTH login with Facebook for my WebAPi service and I am getting the token with the below method:
private static async Task<ExternalLoginData> FromToken(string provider, string accessToken)
{
if (string.IsNullOrEmpty(provider))
return null;
provider = provider.Trim().ToLower();
string verifyTokenEndPoint = "", verifyAppEndpoint = "";
HttpClient client = new HttpClient();
if (provider == ProviderConstants.Facebook)
{
verifyTokenEndPoint = $"https://graph.facebook.com/me?access_token={accessToken}";
verifyAppEndpoint = $"https://graph.facebook.com/app?access_token={accessToken}";
}
else
{
return null;
}
Uri uri = new Uri(verifyTokenEndPoint);
HttpResponseMessage response = await client.GetAsync(uri); <-- exception thrown here
if (response.IsSuccessStatusCode)
{
//not relevant
}
//not relevant
}
The exception is not thrown on local development server on any configuration. But it fails on the live server with the below error.
Any idea why?
Failed when generating token
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 1.1.1.1:443
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at FishingApp.Controllers.AccountController.<FromToken>d__32.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 1033
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at FishingApp.Controllers.AccountController.<LoginExternalToken>d__30.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 865
Additional information: looks like I can't connect to the url because I get this error: Unable to connect to the remote server
I was having the same problem since last 5 days, had seen your question 2 days back but that time i didn't had the answer.
Solution:
May be you are using Smarterasp.net as your hosting provider.
They introduced an additional setting in "Security Tab" , where they are rejecting any internal connection going to graph.facebook.com by default. But if you need this, you have to "Enable" this setting.
Smarterasp Snapshot
Good Luck

ASP.NET 5 Failing to install ASP.NET 5 NuGet Package

I have a ASP.NET 5 NuGet package called Boilerplate.Web.Mvc6. I am unable to to reference the NuGet package in my ASP.NET 5 website. Here is my project.json file referencing "Boilerplate.Web.Mvc6": "1.0.11".
{
// Omitted
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta6",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta6",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta6",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6",
"Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-beta6",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta6",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta6",
"Microsoft.Framework.Logging": "1.0.0-beta6",
"Microsoft.Framework.Logging.Console": "1.0.0-beta6",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta6",
"Newtonsoft.Json": "7.0.1",
"System.Runtime": "4.0.20-beta-23109",
"Boilerplate.Web.Mvc6": "1.0.11"
},
// Omitted
}
When I add the package above, the references in the project shows an error and I get the following printed in the output window:
PATH=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\git
C:\Users\Rehan Saeed\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7-12364\bin\dnx.exe "C:\Users\Rehan Saeed\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7-12364\bin\lib\Microsoft.Dnx.Tooling\Microsoft.Dnx.Tooling.dll" restore "C:\Temp\WebApplication2\WebApplication2" -f "C:\Program Files (x86)\Microsoft Web Tools\DNU"
Microsoft .NET Development Utility CLR-x86-1.0.0-beta7-12364
Restoring packages for C:\Temp\WebApplication2\WebApplication2\project.json
CACHE https://api.nuget.org/v3/index.json
CACHE http://MyGet.org/aspnetmaster/
CACHE https://az320820.vo.msecnd.net/v3-flatcontainer/boilerplate.web.mvc6/index.json
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
Warning: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
Warning: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
Error: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
----------
System.IO.InvalidDataException: Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response. ---> System.Xml.XmlException: 'doctype' is an unexpected token. The expected token is 'DOCTYPE'. Line 2, position 3.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2)
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
at Microsoft.Dnx.Tooling.Restore.NuGet.NuGetv2Feed.EnsureValidFindPackagesResponse(Stream stream, String uri)
--- End of inner exception stack trace ---
at Microsoft.Dnx.Tooling.Restore.NuGet.NuGetv2Feed.EnsureValidFindPackagesResponse(Stream stream, String uri)
at Microsoft.Dnx.Tooling.Restore.NuGet.NuGetv2Feed.<>c__DisplayClass25_0.<FindPackagesByIdAsyncCore>b__0(Stream stream)
at Microsoft.Dnx.Tooling.Restore.NuGet.HttpSource.<GetAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Dnx.Tooling.Restore.NuGet.NuGetv2Feed.<FindPackagesByIdAsyncCore>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RemoteWalkProvider.<FindLibrary>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<FindLibrary>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<FindLibraryByVersion>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<FindLibraryMatch>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<FindLibraryEntry>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<CreateGraphNode>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Dnx.Tooling.RestoreOperations.<CreateGraphNode>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreCommand.<CreateGraphNode>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Dnx.Tooling.RestoreCommand.<RestoreForProject>d__70.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreCommand.<>c__DisplayClass69_0.<<Execute>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dnx.Tooling.RestoreCommand.<Execute>d__69.MoveNext()
----------
Restore failed
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
NuGet Config files used:
C:\Users\Rehan Saeed\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
https://az320820.vo.msecnd.net/v3-flatcontainer/
http://MyGet.org/aspnetmaster/
C:\Program Files (x86)\Microsoft Web Tools\DNU
What's going wrong?
UPDATE
These are my NuGet package feeds:
nuget.org - https://api.nuget.org/v3/index.json
My Get - http://MyGet.org/aspnetmaster
Microsoft .NET - https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/
UPDATE 2
I ran dnu restore --ignore-failed-sources and got the following output, where it still can't find my NuGet package. The strange thing is that I can reference 1.0.10 of the same package from my ASP.NET 5 project but not from an ASP.NET 5 class library.
Restoring packages for C:\Temp\WebApplication2\WebApplication2\project.json
GET https://api.nuget.org/v3/index.json
OK https://api.nuget.org/v3/index.json 130ms
GET http://MyGet.org/aspnetmaster/
OK http://MyGet.org/aspnetmaster/ 142ms
GET https://az320820.vo.msecnd.net/v3-flatcontainer/boilerplate.web.mvc6/index.json
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
Warning: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
OK https://az320820.vo.msecnd.net/v3-flatcontainer/boilerplate.web.mvc6/index.json 103ms
Warning: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
GET http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6'
Warning: FindPackagesById: Boilerplate.Web.Mvc6
Response from http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' is not a valid NuGet v2 service response.
Unable to locate Boilerplate.Web.Mvc6 >= 1.0.11
Writing lock file C:\Temp\WebApplication2\WebApplication2\project.lock.json
Restore complete, 1210ms elapsed
Errors in C:\Temp\WebApplication2\WebApplication2\project.json
Unable to locate Boilerplate.Web.Mvc6 >= 1.0.11
NuGet Config files used:
C:\Users\Rehan Saeed\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
https://az320820.vo.msecnd.net/v3-flatcontainer/
http://MyGet.org/aspnetmaster/
It might be a myget bug. I opened a bug on dnu anyway (see it here) and also pinged the myget folks.
The issue is that http://MyGet.org/aspnetmaster/FindPackagesById()?id='Boilerplate.Web.Mvc6' returns 200 OK and HTML when the package is not found and we try to parse it as XML.
You can pass --ignore-failed-sources to dnu restore to unblock yourself.
I have tried deleting the project.lock.json file and re-opening Visual Studio which usually solves this problem for me.
I have since retried installing version 1.0.11 of the package and it magically worked. Since previous versions were working and I made no changes to the project or my installation, I suspect this to be a NuGet package on-boarding problem. It has taken three days for NuGet to register the new version of the package.