In troubleshooting AddTagsCollection Action behavior in a controller, I have a strange scenario which I have not encountered before, its not even a multi threaded section. The Visual Studio Debugger enters the function till the first line string alert = ""; and even stops at the debugger but never goes on to the other lines!!
public JsonResult AddTagsCollection(int collectionID, string Name, string Description, string Order, bool IsActive, bool RootUseOnly)
{
// Yes hits this break point only then bails out - whats going on??
string Alert = "";
// NEVER hits this break point
if (ProfileTagCollection.GetByName(Name.Trim()).ProfileTagCollectionID > 0)
Alert = "The collection \"" + Name + "\" already exists.";
// NEVER hits this break point!!!
var testme = "test";
// NEVER hits this break point - you get the idea, it just return back to the HTML view??
if (Name.Trim().ToLower().Length == 0)
Alert = "The collection name should not be empty.";
if (Alert != "")
{
RequestResultModel _model = new RequestResultModel();
_model.InfoType = RequestResultInfoType.ErrorOrDanger;
_model.Alert = Alert;
AuditEvent.AppEventWarning(Profile.Member.Email, Alert);
return Json(new
{
NotifyType = NotifyType.DialogInline,
Html = this.RenderPartialView(#"_RequestResultDialogInLine", _model),
}, JsonRequestBehavior.AllowGet);
}
ProfileProfileTagCollection ProfileTagCollection = new ProfileProfileTagCollection();
tagCollection.OrderID = 0;
tagCollection.tagCollectionName = Name;
tagCollection.tagCollectionDescription = Description;
tagCollection.IsActive = IsActive ? 1 : 0;
tagCollection.RootUseOnly = RootUseOnly ? 1 : 0;
tagCollection.Save();
if (collectionID > 0)
AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" profile collection has been updated.", Name));
else
AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" profile collection has been added.",Name));
if (Order != "")
{
Order = Order.Replace("this", tagCollection.tagCollectionID.ToString());
ProfiletagCollections.UpdateOrder(Order);
}
// I have tried passing other combinations to reach here, but why does it not get here
return Json(new {
NotifyType = -1,
Html = "",
}, JsonRequestBehavior.AllowGet);
}
I also tried to lookup the debug windows module, in 2013 its not listed, has it moved... In debug mode, select debug->windows->modules (modules is missing for me)
Can you help me with why the debugger does not hit the break point and what steps I can take to resolve or investigate this?
I think you could use this
You probably are after something like this:
if(System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break(); Of course that will still get
compiled in a Release build. If you want it to behave more like the
Debug object where the code simply doesn't exist in a Release build,
then you could do something like this:
[Conditional("DEBUG")] void DebugBreak() {
if(System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break(); } Then add a call to it in your code.
Related
I am facing an stranger issue when I try to debug one of my api via Swagger. If I remove the debugger points, the swagger automatically closes without showing the output. However, if I add debugger points, the debugger stops working and a pop-up is displayed showing the message the target process exited with code 1073741819 while evaluating a function.
Here is the pop-up that I have mentioned:
Here is the api that I am getting this issue on:
[HttpGet("feerate")]
public async Task<ActionResult<ResponseVM>> GetFeeRate(FeeName feeName, FeeSchedule feeSchedule, FeeUnit feeUnit, int vcu)
{
try
{
var rv = await service.GetFeeRate(feeName, feeSchedule, feeUnit, vcu);
return Ok(new ResponseVM
{
success = true,
data = rv,
message = "Fee rate fetched successfully"
});
}
catch (Exception ex)
{
return Ok(new ResponseVM
{
success = false,
message = ex.Message
});
}
}
Here is the service function:
public async Task<PaginatedResponseVM<FeeScheduleDto>> GetFeeRate(FeeName feeName, FeeSchedule feeSchedule, FeeUnit feeUnit, int vcu)
{
var accQueryList = _dbContext.FeeSchedule.Where(x => x.FeeSchedule == feeSchedule);
accQueryList = accQueryList.Where(x => x.FeeName == feeName);
accQueryList = accQueryList.Where(x => x.FeeUnit == feeUnit);
accQueryList = accQueryList.Where(x => x.TierStart <= vcu);
accQueryList = accQueryList.Where(x => x.TierEnd > vcu);
var count = await accQueryList.CountAsync();
var items = _mapper.Map<List<FeeScheduleDto>>(await accQueryList.ToListAsync());
var returnView = new PaginatedResponseVM<FeeScheduleDto>(count, items);
return returnView;
}
Here is what I tried to resolve it:
Restarted my PC
Upgraded Visual Studio version
Repaired the Visual Studio via Control Panel
Cleaned the solution and Rebuild it
But the issue persists, so is there anyone who faced a similar issue and how it was resolved?
Any help would be appreciated.
Everyone thank you for all your replies and insights. However, the problem was with my Enum that I had used in the Dto file in the wrong manner. As the pop-up error says, I had to check again and again and at last correct my silly mistake.
So, while the enum is converted to string, the enum variable should be converted to string rather than the returning string variable itself.
Here is the correct way:
public FeeScheduleEnum FeeSchedule { get; set; }
public string FeeScheduleName { get { return FeeSchedule.ToString(); } }
So, this is where I had done that silly mistake:
public FeeScheduleEnum FeeSchedule { get; set; }
public string FeeScheduleName { get { return FeeScheduleName.ToString(); } }
Posting my answer here for anyone else doing that same mistake as I did.
I have a procedure in my code where it does some data validation and then calls a SAVE function. The SAVE function writes the validated data to the database. If I but a code break BEFORE the SAVE function is called and then stop debugging, the data is STILL being saved in the database (i.e. the SAVE function is STILL being run). I validated this because if I comment out the call to the SAVE function, and do the same as described above, nothing gets saved.
Here is an example of my code:
protected bool Savedata()
{
string newpostingid = "";
bool isSaved;
int SaveError = 0;
postingid = 0;
string description = "";
string RequiredSkills = "";
string Certifications = "";
string Travel = "";
string duration = "";
string WIIFY = "";
string postingdate = "1/1/2000";
DateTime? fromdate = validate_date(From_Date.Text);
DateTime? todate = validate_date(To_Date.Text);
DateTime? startdate = validate_date(Start_Date.Text);
if (RequiredSkillsTextBox.Text != "") { RequiredSkills = RequiredSkillsTextBox.Text; }
if (CertificationsTextBox.Text != "") { Certifications = CertificationsTextBox.Text; }
if (WIIFYTextBox.Text != "") { WIIFY = WIIFYTextBox.Text; }
newpostingid =
jdh.UpdatePosting(
Convert.ToInt32(OpportunityTypeDropDownList.SelectedValue),//PostingTypeID
Server.HtmlEncode(OpportunityTitleTextBox.Text),//PostingTitle
Convert.ToInt32(SalaryGradeDropDownList.SelectedValue),//SalaryGrade
Convert.ToInt32(DisciplineDropDownList.SelectedValue),//LOBMFOID
);
)
In the above code snippet, If I put a break BEFORE the newpostingid = jdh.UpdatePosting, and stop debugging when it hits the break, the newpostingid = jdh.UpdatePosting still gets called. As I indicated above, commenting out the newpostingid section, nothing gets saved when I stop debugging.
To Start Debugging you usually use the green Play Icon or F5
If you put a Breakpoint anywhere in your code, the debugger stops the execution there.
It only pauses the execution and doesnt stop it, thats why the correct Terminus for it is Breakpoint not Break. The line will be marked Red and a Red dot will appear at the lefthand side of your line.
However to Stop the Debugging, you will need to eiter press the Stop Debugging Button or
Shift + F5 which will do the same.
You can use Step Into F10 or Step Over F11 to step by step proceed the code execution. If you press F5 while debugging, it will proceed to the next Breakpoint or until the end of your program execution.
Hope this helps with your struggles.
I made a request to get a specific single value property from all events in a calendar with the Graph-SDK. To achieve this i used a filter according to the Graph APIs documentation (https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/singlevaluelegacyextendedproperty_get). The filter i used was " id eq 'Boolean {00062002-0000-0000-C000-000000000046} Id 0x8223' ". Below is the code i used for this request.
public static async Task<Tuple<List<Event>, List<ICalendarEventsCollectionRequest>>> GetEventsSingleValuePropertyAsync(GraphServiceClient graphClient, String userId, String calendarId, String filterQuery, int top, String select)
{
List<ICalendarEventsCollectionRequest> requestList = new List<ICalendarEventsCollectionRequest>();
// filterQuery = "id eq 'Boolean {00062002-0000-0000-C000-000000000046} Id 0x8223'"
String filterSingleVP = "singleValueExtendedProperties($filter=" + filterQuery + ")";
List<Event> eventList = new List<Event>();
ICalendarEventsCollectionPage result = null;
ICalendarEventsCollectionRequest request = null;
if (calendarId == "")
request = graphClient.Users[userId].Calendar.Events.Request().Expand(filterSingleVP).Top(top).Select(select);
else
request = graphClient.Users[userId].Calendars[calendarId].Events.Request().Expand(filterSingleVP).Top(top).Select(select);
try
{
if (request != null)
{
result = await request.GetAsync();
requestList.Add(request);
eventList.AddRange(result);
}
if (result != null)
{
var nextPage = result;
while (nextPage.NextPageRequest != null)
{
var nextPageRequest = nextPage.NextPageRequest;
nextPage = await nextPageRequest.GetAsync();
if (nextPage != null)
{
requestList.Add(nextPageRequest);
eventList.AddRange(nextPage);
}
}
}
}
catch
{
throw;
}
return new Tuple<List<Event>, List<ICalendarEventsCollectionRequest>>(eventList, requestList);
}
I get all events and every event that matched the query gets expanded with the SingleValueLegacyExtendedProperty. The only thing that bothers me is that it looks like this:
"singleValueExtendedProperties":
[
{
"value":"true",
"id":"Boolean {00000000-0000-0000-0000-000000000000} Id 0x8223"
}
],
As you can see the value is present but the id now has an empty GUID.
I tested some other properties but i always had the same result.
I thought my filter compares the given "filterQuery" with the "id" in the answer.
Did i misunderstand something or is my request implementation just wrong?
That just looks like a bug on our side. Seems like the Guid prop might not be getting set or serialized correctly. I will bring it up to the team - thanks for the report.
-edit-
Yep, in fact we already have a fix for this that should be checked in in a few days.
-edit, edit-
Just for education's sake, the reason that it behaves this way is that the GUID that you are using is one of the "well known guids". In that case, our code is setting the well-known GUID field internally instead of the normal propertySetId guid field and REST always uses the propertySetId when rendering responses. The fix of course on our side is to use the well known guid field if the propertySetId is Guid.Empty.
-edit,edit,edit-
A fix was checked in for this and will begin normal rollout. It should reach WW saturation in a few weeks.
this code:
try{
_player.Stop();
_player.Release();
_player.Dispose();
_player = null;
}
catch( Exception)
{
}
}
only works if I put a breakpoint at _Player.Stop(). why? I am using Xamarin Studio it I do not use a breakpoint it says: 'jobject' must not be IntPtr.Zero. Parameter name: jobject
what does that mean ? and why does it only work if I have a break point ?
also it does not like this
if ( _Play.Isplaying) // it always give me this error : IntPtr.Zero. Parameter name: jobject
button.Click += delegate {
if( flag == 1)
{
return;
}
ThreadPool.QueueUserWorkItem(o=> Stopped());
int temp = Convert.ToInt16(test1.Text) ;
temp = temp * 44100 *60 *2;
if( tone1 ==0)
{
trackW = new whitenoise(temp);
trackW.Frequency = Num; //Convert.ToDouble(Beattext.Text);
ThreadPool.QueueUserWorkItem(o=> trackW.play());
flag = 1;
}else if (tone1 ==1)
{
trackP = new PinkNoise(temp);
trackP.Frequency = Num;//Convert.ToDouble(Beattext.Text);
ThreadPool.QueueUserWorkItem(o=> trackP.play());
flag = 1;
}
else if (tone1 ==2 )
{
trackB = new BrownNoise(temp);
trackB.Frequency =Num;// Convert.ToDouble(Beattext.Text);
ThreadPool.QueueUserWorkItem(o=> trackB.play());
flag = 1;
}
else if (tone1 ==3 )
{
_player = MediaPlayer.Create(this, Resource.Raw.dark);
_player.Start();
//flag = 1;
}
else if (tone1 ==4 )
{
_player2 = MediaPlayer.Create(this, Resource.Raw.thunder);
_player2.Start();
//flag = 1;
}
};
In Xamarin.iOS MediaPlayer is a namespace, not a type. So it's unclear which type is being created with:
_player = MediaPlayer.Create(this, Resource.Raw.dark);
Now several media-related types are asynchronous, i.e. when you call Stop it will ask the player to stop and then return immediately. IOW you'll get back control before the actual stop action is completed. That likely explain why putting a breakpoint make your code works (it introduce delays that make it looks like it works synchronously).
_player.Release();
Don't ever call Release manually (there should be a compiler warning for that line). It's required in very special circumstances where you're doing manual memory management (e.g. calling Retain). That's very low level (XI internals needs it) and very rarely required in user code.
_player.Dispose();
That's also not the right place to call Dispose as the Stop might not have completed it's job (and disposing the instance could create problem as it's still being used, stopping, natively). Some types provide events that will tell you when things (like stop) actually happens. Even then you might just want to let the GC do it's job.
I am testing to see whether the user has cookies turned on and I don't seem to be doing something right.
Here is my test:
private bool CookiesAllowed()
{
var testCookie = new HttpCookie("TestCookie", "abcd");
System.Web.HttpContext.Current.Response.Cookies.Set(testCookie);
var tst = System.Web.HttpContext.Current.Request.Cookies.Get("TestCookie");
if (tst == null || tst.Value == null)
{
return false;
}
return true;
}
I'm putting a cookie out there... and then getting it back. But it always succeeds.
Here is how I'm disabling them:
I go to Gmail and it tells me my cookies are disabled so I believe I am doing that part right.
What am I doing wrong?
EDIT
To answer James' question, I am calling this from my logon screen, which is my entry screen as the first check:
public ActionResult LogOn(string id)
{
if (!CookiesAllowed())
{
return View("CookiesNotEnabled");
}
Also, I have tested this live, outside of visual studio and not at localhost and it did the same thing.
You have to let your client/browser do a new Request in order to see if you get the cookie back. When you add a Cookie to the response object, you can only check the presence of it in subsequent new Requests.
Here's a way to do it within the same page in ASP.NET WebForms (since I saw your edit indicating you are using MVC):
private bool IsCookiesAllowed()
{
string currentUrl = Request.RawUrl;
if (Request.QueryString["cookieCheck"] == null)
{
try
{
var testCookie = new HttpCookie("SupportCookies", "true");
testCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(testCookie);
if (currentUrl.IndexOf("?", StringComparison.Ordinal) > 0)
currentUrl = currentUrl + "&cookieCheck=true";
else
currentUrl = currentUrl + "?cookieCheck=true";
Response.Redirect(currentUrl);
}
catch
{
}
}
return Request.Cookies.Get("SupportCookies") != null;
}
This code snippet is inspired by this thread.