When I programmatically create a new bug and set the area path to this:
VssBasicCredential credentials = new VssBasicCredential(string.Empty, personalAccessToken);
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.AreaPath",
Value = "Project"
},
WorkItem bug = await workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").ConfigureAwait(false);
I get this error:
TF401346: Invalid Area/Iteration id given for work item -1, field 'System.AreaId'.
I think this is a bug, this area path exists in ADO.
The issue was not the area path but another field, for whatever reason ADO pointed to the area path as the issue. Try adding each field one by one, or area field alone to see if it fixes the issue. This is the trimmed down version of my code.
JsonPatchDocument patchDocument = new JsonPatchDocument
{
//add fields and their values to your patch document
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Title",
Value = $"{tag} for PR #{pullRequest.PullRequestId} changes in build {buildNumber} PlannerBuildArtifact."
},
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.AreaPath",
Value = "Project\\Planner\\Service"
}
};
try
{
using VssConnection connection = new VssConnection(Uri, this._credentials);
using WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
return await workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, Project, "Bug").ConfigureAwait(false);
}
catch (VssException e)
{
_log.LogError("Unable to create work item", e);
throw;
}
Related
I have an error occurring that I can't seem to find anything about. When I run my code I get the following error. I am not setting oDataType so I assume this is something done by the api itself.
ServiceException: Code: RequestBodyRead Message: The property 'oDataType' does not exist on type microsoft.graph.itemBody'. Make sure to only use property names that are defined by the type or mark the type as open type.
My code is mostly copied from microsoft samples.
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
client = new GraphServiceClient(authenticationProvider);
var message = new Microsoft.Graph.Message()
{
Subject = "Test email",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Test email."
},
HasAttachments = false,
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "myemail#mydomain.com"
}
}
}
};
var saveToSentItems = false;
await client.Users[userID].SendMail(message, saveToSentItems).Request().PostAsync();
Any help would be greatly appreciated.
Thank you
I suspect, you're using a older library/build. I remember the related issue and it's fixed last year itself.
Please update it with the latest one , try testing the same and let us know if you can still repro the issue or not.
I want to create a specific class of assignments.
At Graph Explorer,
https://graph.microsoft.com/beta/education/classes/{classId}/assignments
This request works well.
But in my C# code,
var assignInfo = new EducationAssignment
{
DisplayName = "test",
DueDateTime = DateTimeOffset.Parse("2020-09-20T18:00:00Z"),
Instructions = new EducationItemBody
{
ContentType = BodyType.Html,
Content = "hi"
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true,
AssignTo = new EducationAssignmentClassRecipient
{
},
Grading = new EducationAssignmentPointsGradeType()
{
MaxPoints = 100
},
CreatedDateTime = DateTimeOffset.Parse("2020-09-20T12:00:00Z"),
AssignDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
AssignedDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
CloseDateTime = null,
AllowLateSubmissions = true
};
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.AddAsync(assignInfo);
It occured error:
{"Code: 20132\r\nMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2020-09-20T07:25:14\r\n\trequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n\tclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\nClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n"}
Why is this happening? I've been thinking and trying all day.
I tried
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.Header("Content-Type", "application/json")
.AddAsync(assignInfo);
But there was the same error.
If only the displayname element was requested, the results were the same.
The Permissions has been dealt with.
EduAssignments.ReadWriteBasic, EduAssignments.ReadWrite.. etc
And the dll(NuGet pakage) is also prepared in beta version.
I referred to this document.
I'm desperate for help..
Thanks.
adding this assignInfo.ODataType = null; fixes the problem.
Could someone please help what does this error means
is it some connection issue?
operation performed on onpremise tfs server
here i am using TFS personal access token to do authorize operations.
Here is a code snippet creating a Bug work item in DevOps using HttpClient library, for your reference:
public class CreateBug
{
readonly string _uri;
readonly string _personalAccessToken;
readonly string _project;
public CreateBug()
{
_uri = "https://xxx.visualstudio.com";
_personalAccessToken = "xxx";
_project = "xxxxx";
}
public WorkItem CreateBugUsingClientLib()
{
Uri uri = new Uri(_uri);
string personalAccessToken = _personalAccessToken;
string project = _project;
VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
JsonPatchDocument patchDocument = new JsonPatchDocument();
//add fields and thier values to your patch document
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Title",
Value = "Authorization Errors"
}
);
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/Microsoft.VSTS.Common.Priority",
Value = "1"
}
);
VssConnection connection = new VssConnection(uri, credentials);
WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
try
{
WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result;
Console.WriteLine("Bug Successfully Created: Bug #{0}", result.Id);
return result;
}
catch (AggregateException ex)
{
Console.WriteLine("Error creating bug: {0}", ex.InnerException.Message);
return null;
}
}
}
Due to error message text was having encoding issue, was not able to figure out the issue, Did debug on server and found out TTFS url with collection was not forming properly hence it was giving "page not found" error message, after that we fixed it by updating the tfs api url.
I am trying to upload an image on google drive using webapi. I copied the following chunk from Google drive doc but I am getting an error.
Here is the code:
var clientSecret = ConfigurationManager.AppSettings["GoogleDriveClientSecret"];
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret },
scopes, Environment.UserName, CancellationToken.None).Result;
var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential });
var folderId = "0B2bBiMQICgHCMlp6OUxuSHNaZFU";
var fileMetadata = new File()
{
Name = "photo.jpg",
Parents = new List<string>
{
folderId
}
};
FilesResource.CreateMediaUpload request;
using (var stream = new System.IO.FileStream("files/photo.jpg",
System.IO.FileMode.Open))
{
request = service.Files.Create(
fileMetadata, stream, "image/jpeg");
request.Fields = "id";
request.Upload();
}
var file = request.ResponseBody;
Now I am getting 2 errors in this code. First "Cannot resolve symbol Upload" at request.Upload() and second "Cannot resolve symbol ResponseBody" at request.ResponseBody
Any help?
You may refer with this related thread. The adding the attribute Inherits="Library.Account.RootVerifyUsers". Based from this reference, Visual Studio can often get confused about things like this. It is recommended to close Visual Studio and reopen it. Also, closing all open instances of VS may be required.
I can not pass values to the report.
This is my code:
public void GLRPT()
{
try
{
ReportClass rptH = new ReportClass();
rptH.FileName = Server.MapPath("~/Rpts/G1.rpt");
rptH.Load();
string df = Session["fromdate"].ToString();
string dt = Session["todate"].ToString();
DateTime fromdate = DateTime.Parse(df);
DateTime todate = DateTime.Parse(dt);
rptH.SetParameterValue("?Date_From", fromdate);
rptH.SetParameterValue("?Date_To", todate);
rptH.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "GL");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
I don't know why I see this error:
Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
We should pass the parameter value like this:
rptH.SetParameterValue("Date_From", fromdate); //correct
NOT
rptH.SetParameterValue("?Date_From", fromdate); //incorrect
Then we we must give database access to the report because without login to database the report will not be opened.
and here is the code:
ReportDocument rptH = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
rptH.Load(Server.MapPath("~/Rpts/G1.rpt"));
string df = Session["fromdate"].ToString();
string dt = Session["todate"].ToString();
DateTime fromdate = DateTime.Parse(df);
DateTime todate = DateTime.Parse(dt);
rptH.SetParameterValue("Date_From", fromdate);
rptH.SetParameterValue("Date_To", todate);
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = rptH.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
rptH.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "GL");
We must call the parameter's name without any additional character such as
# or ?, just only the parameter's name itself.
I know the topic a little bit old, but it might help for someone if I share my experience.
As we can read in many topics, "the parameters name are different in the report file and the code". Yes this is true, but it is also happens if you added or removed parameters from the report file and forgot to copy the new file into your application location.
It would be the Visual Studio job, but sometimes the VS forget to copy the modified report file to the "Debug" folder, I think.
The point of this writing, after you modified your report file, regarding parameters, copy it into your compiled location.