|
I tried as you said
var d = new StreamReader(await this.ActionContext.Request.Content.ReadAsStreamAsync());
Quote Selected Text
Still same exception is throwing i guess some where problem with Task
|
|
|
|
|
The formatting is a bit all over the place so it's hard to read, but this should also be async:
protected async Task LogErrorAsync(string controller, string action, string message, string stacktrace, string user = "")
{
QuotationDBFactory mFactory = new QuotationDBFactory();
mFactory.InsertErrorLog(
user,
controller,
action,
message,
stacktrace
);
await SendEmailAysnc(stacktrace, message);
}
and then:
try{
Task.Run(() =>
{
SendMailForGSSCQuotes(mDBEntity.QUOTATIONNUMBER.ToString(), Convert.ToInt32(mDBEntity.ThresholdQty), Convert.ToInt32(mDBEntity.ISHAZARDOUSCARGO), Convert.ToInt32(mDBEntity.HASMISSINGCHARGES));
}).ConfigureAwait(false);
}
catch(Exception ex){
Task.Run(() =>
{
LogErrorAsync("api/Quotation", "SendMail", ex.Message.ToString(), ex.StackTrace.ToString());
});
}
|
|
|
|
|
I tried the same as you mention still no luck.Same error throwing
|
|
|
|
|
Why we choose Task.Run to render the UI First then we will run remaining methods.here chosse task.run its working fine as per requirement when coming back to global error its broken as my guess the object is dispose when UI as render so no where to run the
ReadAsStreamAsync
|
|
|
|
|
I am very new to coding and had to write a code for my college project referring to a YouTube video. So far everything I have written is fine but only one error seems to repeat itself which is: 'Statement is not valid n a namespace'
Please help..
Option Explicit On
Dim BUFFERSS
Private Declare Sub Sleep Lib "kernel132" (ByVal dwMilliseconds As Long)
Dim message As Integer<small><big><pre>
Dim search As String
Dim strTest As String
Dim user1 As Integer
Dim user2 As Integer
Dim time1 As Integer
Dim time2 As Integer
Dim mins As Integer
Dim secs As Integer
Dim teacherflag As Integer
Dim sflag1 As Integer ' Student 1 flag
Dim sflag2 As Integer ' Student 2 flag
Dim sflag3 As Integer ' Student 3 flag
Dim msending As Integer ' message sending flag
Dim absent1 As Integer
Dim absent2 As Integer
Dim absent3 As Integer
Dim absentflag As Integer
Dim flag1 As Integer
Dim flag2 As Integer
Dim flag3 As Integer
Dim counter As Integer
Private Sub Form_Load()
mins = 0
Timer3.Enabled = False
teacherflag = 0
sflag1 = 0
sflag2 = 0
sflag3 = 0
msending = 0
absent1 = 0
absent2 = 0
absent3 = 0
absentflag = 0
flag1 = 0
flag2 = 0
flag3 = 0
PerformanceCounter = 0
'MSComm1.Settings = "9600,n,8,1" 'Change this with the Baud rate of your modem (The one that you use with the Hyper terminal)
'MSComm1.CommPort = 10
'MSComm1.PortOpen = True
With MSComm1
.CommPort = 3
.Settings = "9600,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.Rthreshold = 1
.Sthreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True 'Must be the last
End With
End Sub
Private Sub Timer1_Timer()
txtrec.Text = MSComm1.Input
SearchDirectionHint = txtrec.Text
If (InStr(search, "teacher") And (teacherflag = 0)) Then ' when the teacher will swipe the RFID card word teacher will be
Check3.Value = 1
Timer3.Enabled = True 'timer3 is used for timing mins and secs
teacherflag = 1
Timer4.Enabled = True
End If
If (InStr(search, "stu1") And (sflag1 = 0) And mins < 6) Then 'then the student 1 will be marked present
Check4.Value = 1
sflag1 = 1
End If
If (InStr(search, "stu2") And (sflag1 = 0) And mins < 6) Then 'then the student 2 will be marked present
Check5.Value = 1
sflag2 = 1
End If
If (InStr(search, "stu3") And (sflag1 = 0) And mins < 6) Then 'then the student 3 will be marked present
Check6.Value = 1
sflag3 = 1
End If
End Sub
Private Sub Timer2_Timer()
Label5.Caption = TimeOfDay
End Sub
Private Sub Timer3_Timer()
secs = secs + 1
Label7.Caption = Secs
If secs > 59 Then
secs = 0
mins = mins + 1
Label3.Caption = mins
End If
End Sub
Private Sub Timer4_Timer()
'sending message to students to let them know that the teacher has arrived.
'in the controller program each and every user will have its own message sending function in which his number will be specified
PerformanceCounter = PerformanceCounter + 1
Label3.Caption = PerformanceCounter
If ((teacherflag = 1) And ((PerformanceCounter > 10) And (PerformanceCounter < 20)) And (Check8.Value = 0)) Then
Check8.Value = 1
End If
If ((teacherflag = 1) And ((PerformanceCounter > 30) And (PerformanceCounter < 40)) And (Check9.Value = 0)) Then
Check9.Value = 1
End If
If ((teacherflag = 1) And ((PerformanceCounter > 50) And (PerformanceCounter < 60)) And (Check10.Value = 0)) Then
Check10.Value = 1
End If
If ((teacherflag = 1) And ((PerformanceCounter > 90) And (PerformanceCounter < 120)) And (Check12.Value = 0)) Then 'this when checked means all message sent
Check12.Value = 1
End If
'check box for parents messages
If ((Check12.Value = 1) And ((PerformanceCounter > 300) And (PerformanceCounter < 320) And (check4.Value = 0))) Then 'This when checked means all message
Check13.Value = 1
End If
If ((Check12.Value = 1) And ((PerformanceCounter > 330) And (PerformanceCounter < 350) And (check5.Value = 0))) Then 'This when checked means all message
Check14.Value = 1
End If
If ((Check12.Value = 1) And ((PerformanceCounter > 370) And (PerformanceCounter < 380) And (check6.Value = 0))) Then 'This when checked means all message
Check15.Value = 1
End If
If ((Check12.Value = 1) And ((PerformanceCounter > 390) And (PerformanceCounter < 400) And (check7.Value = 0))) Then 'This when checked means all message
Check16.Value = 1
End If
'**************************************************************************
If ((Check8.Value = 1) And (flag1 = 0)) Then
MSComm1.Output = "a"
flag1 = 1
End If
If ((Check9.Value = 1) And (flag2 = 0)) Then
MSComm1.Output = "b"
flag2 = 1
End If
If ((Check10.Value = 1) And (flag3 = 0)) Then
MSComm1.Output = "c"
flag3 = 1
End If
'message sending to their parents
If ((Check13.Value = 1) And (Absent1 = 0)) Then
MSComm1.Output = "l"
Absent1 = 1
End If
If ((Check14.Value = 1) And (Absent2 = 0)) Then
MSComm1.Output = "m"
Absent2 = 1
End If
If ((Check15.Value = 1) And (Absent3 = 0)) Then
MSComm1.Output = "n"
Absent = 1
End If
End Sub
Sameer
|
|
|
|
|
It looks like you've chosen a really bad video to follow. That looks more like VB6 code than VB.NET.
Assuming you're actually using VB.NET, try some VB.NET tutorials instead:
Visual Basic development with Visual Studio - Visual Studio | Microsoft Docs[^]
The obvious problem is that you're putting variables and functions directly within the code file. In VB.NET, they need to be within a Class or Module . Looking at the code you've posted, it needs to be within the Class that defines your form.
NB: If you're actually using VB6, then don't! VB6 has been effectively "dead" for almost 20 years now.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks a lot!
And yes, you are right I am using VB.NET.
|
|
|
|
|
Hi,
I am writing unit tests for my application, I have a Service call which I wanna mock, the my method takes list of some type and converts that type into another type of objects then calls another back-end Service which we have only Proxy class but don't know much about it, for each item in the list - means for each item in the list we pass, it will be converted and then passed to that black-box service that we don't know anything about, our method returns nothing, I mean this methods is void method.
If Service call fails for any one item in the list, our our method throws Exception aborts calls to all the remaining items, that's all it does, its simple for implementation but for writing Unit Tests I am having problems.
What I have to check is, weather the conversion of the list of type items that we are passing is done properly or not, and there no response, so I have to mock it, I am trying, but the problem is, how am I going to check for all the items, since the scope of those items that are converted would be within that method call. Its just breaking my head, and I don't want to repeat the mock calls more than what it needs to be. Any help would be greatly greatly helpful - thanks in advance.
My Test method that I am trying:
[TestMethod]
public async Task ServiceAgreementUpdateAddTest()
{
var serviceAgreementCharacteristicRequests = new List<ServiceAgreementCharacteristicRequest>();
foreach (var serviceAgreementId in this.serviceAgreementIds)
{
var request = new ServiceAgreementCharacteristicRequest
{
ServiceAgreementId = serviceAgreementId,
CharacteristicType = characteristicType,
CharacteristicValue = characteristicValue,
ActionType = RequestAction.ADD
};
serviceAgreementCharacteristicRequests.Add(request);
}
this._serviceWrapper.Setup(e => e.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>())).ReturnsAsync(new C1ServiceAgreementUpdateResponse());
await this._service.ServiceAgreementCharacteristicAsync(serviceAgreementCharacteristicRequests).ConfigureAwait(false);
this._serviceWrapper.Verify(sw => sw.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()), Times.Exactly(serviceAgreementCharacteristicRequests.Count));
}
My Method is as below:
public async Task ServiceAgreementCharacteristicAsync(List<ServiceAgreementCharacteristicRequest> serviceAgreementCharacteristicRequests)
{
foreach (var item in serviceAgreementCharacteristicRequests)
{
var request = new C1ServiceAgreementUpdateRequest
{
C1ServiceAgreementUpdate = new C1ServiceAgreementUpdate
{
serviceAgreement = item.ServiceAgreementId,
saChar = new[]
{
new C1ServiceAgreementUpdateSaChar
{
action = MapActionType(item.ActionType),
actionSpecified = true,
serviceAgreement11 = item.ServiceAgreementId,
characteristicType3 = item.CharacteristicType,
characteristicValue2 = item.CharacteristicValue,
effectiveDate6 = DateTime.Now,
effectiveDate6Specified = true,
searchCharacteristicValue = SearchCharacteristicValue
}
}
}
};
await this._serviceWrapper.UseServiceAsync((ATC1ServiceAgreementUpdatePortType service) => service.C1ServiceAgreementUpdateAsync(request)).ConfigureAwait(false);
}
}
private listAction MapActionType(RequestAction requestAction)
{
var actionType = listAction.add;
switch (requestAction)
{
case RequestAction.ADD:
break;
case RequestAction.UPDATE:
actionType = listAction.update;
break;
case RequestAction.DELETE:
actionType = listAction.delete;
break;
default:
throw new ArgumentException($"CustomerServiceWeb.Services.ServiceAgreements.ServiceAgreementUpdateProxy.MapActionType: Unmapped CustomerServiceWeb.Domain.Services.Common.RequestAction value: {requestAction.ToString()}");
}
return actionType;
}
modified 8-Feb-19 15:56pm.
|
|
|
|
|
You "mock" the service call, capture the "send" (as XML or whatever), print it or display it, compare it to an "expected output".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
But I am passing args as list to the method that I am going to test but that method loops through each individual item of the list and converts it then calls the service by sending that converted object as an argument.
The problem is how am I going to know the converted object when it is within the scope of the method that I am testing.
You kind of gave me definitely some hint, maybe I am not able to pick it up very well, any code snippet or example link etc, anything helps my friend.
It seems like it is difficult to test these types of Black-box methods (which return void) - and thanks a lot for the support my friend.
One of my Colleague has provided me the below method to do it:
public async Task ServiceAgreementUpdateAddTest()
{
var expectedServiceRequest1 = new C1ServiceAgreementUpdateRequest();
var expectedServiceRequest2 = new C1ServiceAgreementUpdateRequest();
var serviceAgreementCharacteristicRequests = new List<ServiceAgreementCharacteristicRequest>();
foreach (var serviceAgreementId in this.serviceAgreementIds)
{
var request = new ServiceAgreementCharacteristicRequest
{
ServiceAgreementId = serviceAgreementId,
CharacteristicType = characteristicType,
CharacteristicValue = characteristicValue,
ActionType = RequestAction.ADD
};
serviceAgreementCharacteristicRequests.Add(request);
}
this._serviceWrapper.Setup(e => e.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()))
.Callback((Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>> serviceFunc) => { serviceFunc.Invoke(this._serviceAgreementUdateSvc.Object); })
.ReturnsAsync(new C1ServiceAgreementUpdateResponse());
await this._service.ServiceAgreementCharacteristicAsync(serviceAgreementCharacteristicRequests).ConfigureAwait(false);
this._serviceWrapper.Verify(sw => sw.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()), Times.Exactly(serviceAgreementCharacteristicRequests.Count));
this._serviceAgreementUdateSvc.Verify(svc => svc.C1ServiceAgreementUpdateAsync(It.Is<C1ServiceAgreementUpdateRequest>(x =>x.Equals(expectedServiceRequest1))));
this._serviceAgreementUdateSvc.Verify(svc => svc.C1ServiceAgreementUpdateAsync(It.Is<C1ServiceAgreementUpdateRequest>(x => x.Equals(expectedServiceRequest2))));
}
But when I tried to see by putting the breakpoint there, the inside values or attributes of the expectedServiceRequest1 and expectedServiceRequest2 are coming null, I am not understanding how it is working and what is the fix for it. Any help please? Am I doing any mistake or my colleague has not provided me complete code, its spinning my head - need some help please.
modified 8-Feb-19 18:16pm.
|
|
|
|
|
I changed my Test method as below:
[TestMethod]
public async Task ServiceAgreementUpdateAddTest()
{
DateTime dateTime = DateTime.Today;
var expectedServiceRequest1 = new C1ServiceAgreementUpdateRequest
{
C1ServiceAgreementUpdate = new C1ServiceAgreementUpdate
{
serviceAgreement = this.serviceAgreementIds[0],
saChar = new[]
{
new C1ServiceAgreementUpdateSaChar
{
action = listAction.add,
actionSpecified = true,
serviceAgreement11 = this.serviceAgreementIds[0],
characteristicType3 = characteristicType,
characteristicValue2 = characteristicValue,
effectiveDate6 = dateTime,
effectiveDate6Specified = true,
searchCharacteristicValue = searchCharacteristicvalue
}
}
}
};
var expectedServiceRequest2 = new C1ServiceAgreementUpdateRequest
{
C1ServiceAgreementUpdate = new C1ServiceAgreementUpdate
{
serviceAgreement = this.serviceAgreementIds[0],
saChar = new[]
{
new C1ServiceAgreementUpdateSaChar
{
action = listAction.add,
actionSpecified = true,
serviceAgreement11 = this.serviceAgreementIds[1],
characteristicType3 = characteristicType,
characteristicValue2 = characteristicValue,
effectiveDate6 = dateTime,
effectiveDate6Specified = true,
searchCharacteristicValue = searchCharacteristicvalue
}
}
}
};
var serviceAgreementCharacteristicRequests = new List<ServiceAgreementCharacteristicRequest>();
foreach (var serviceAgreementId in this.serviceAgreementIds)
{
var request = new ServiceAgreementCharacteristicRequest
{
ServiceAgreementId = serviceAgreementId,
CharacteristicType = characteristicType,
CharacteristicValue = characteristicValue,
ActionType = RequestAction.ADD
};
serviceAgreementCharacteristicRequests.Add(request);
}
this._serviceWrapper.Setup(e => e.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()))
.Callback((Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>> serviceFunc) => { serviceFunc.Invoke(this._serviceAgreementUdateSvc.Object); })
.ReturnsAsync(new C1ServiceAgreementUpdateResponse());
await this._service.ServiceAgreementCharacteristicAsync(serviceAgreementCharacteristicRequests).ConfigureAwait(false);
this._serviceWrapper.Verify(sw => sw.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()), Times.Exactly(serviceAgreementCharacteristicRequests.Count));
}
I am getting the following error:
Failed ServiceAgreementUpdateAddTest
Error Message:
Test method CustomerServiceWeb.Services.Test.ServiceAgreements.ServiceAgreementUpdateProxyTest.ServiceAgreementUpdateAddTest threw exception:
Moq.MockException:
Expected invocation on the mock once, but was 0 times: svc => svc.C1ServiceAgreementUpdateAsync(It.Is<C1ServiceAgreementUpdateRequest>(x => x.Equals(C1ServiceAgreementUpdateRequest)))
Configured setups:
s => s.C1ServiceAgreementUpdateAsync(It.IsAny<C1ServiceAgreementUpdateRequest>())
Performed invocations:
ATC1ServiceAgreementUpdatePortType.C1ServiceAgreementUpdateAsync(C1ServiceAgreementUpdateRequest)
ATC1ServiceAgreementUpdatePortType.C1ServiceAgreementUpdateAsync(C1ServiceAgreementUpdateRequest)
Stack Trace:
at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable`1 setups, IEnumerable`1 actualCalls, Expression expression, Times times, Int32 callCount) in C:\projects\moq4\Source\Mock.cs:line 473
at Moq.Mock.VerifyCalls(Mock targetMock, MethodCall expected, Expression expression, Times times) in C:\projects\moq4\Source\Mock.cs:line 452
at Moq.Mock.Verify[T,TResult](Mock`1 mock, Expression`1 expression, Times times, String failMessage) in C:\projects\moq4\Source\Mock.cs:line 340
at Moq.Mock`1.Verify[TResult](Expression`1 expression, Func`1 times) in C:\projects\moq4\Source\Mock.Generic.cs:line 508
at CustomerServiceWeb.Services.Test.ServiceAgreements.ServiceAgreementUpdateProxyTest.<ServiceAgreementUpdateAddTest>d__8.MoveNext() in C:\SourceCode\FlexPricing\CustomerServiceWeb.Services.Test\ServiceAgreements\ServiceAgreementUpdateProxyTest.cs:line 115
--- End of stack trace from previous location where exception was thrown ---
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.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)
Any help what am I missing?
|
|
|
|
|
That's the "problem" with frameworks: someone else's will on your own ways.
You need a "service stub". You have too much plumbing mixed with app code.
The "service" is app code; the "call" to the server (and its housekeeping) is plumbing.
You create a module to call the service; another that doesn't "call" but uses the "data for the call" as part of the test.
(Previously you queried the server and captured the "expected result" to be used to compare in the unit tests).
You now have input and outputs. You "swap in" (inject) the "service caller" depending on live versus test.
That's it without all the code bloat.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
I am writing some Exception handling to my class, when the Exception is thrown and message or inner exception is not giving us proper information, I have digged into the Detail property of the Exception instance, in the detail under the Nodes, the proper exception is shown in last node. Now I want to log this value, but when I am trying to get the artifacts of the Detail property of the Exception I am getting the error saying Detail is not a property of method of the object Exception.
Please help me how can I read the values of Nodes of the Exception Detail or make this as the Exception message and re-throw the exception if the message or inner-exception values are not correct. Any help would be greatly appreciated.
((System.ServiceModel.FaultException<CustomerServiceWeb.Services.ServiceAgreementUpdateSvc.ouaf.oracle.com.Fault>)ex).Detail.Nodes
|
|
|
|
|
Show your exception handling code. I get the feeling you did something like this
catch (Exception ex)
{
...
}
Correct?
|
|
|
|
|
Yes I did, but for some reason the Detail property is visible in the quick watch but when I try to write it by using the intellisense and get those on the screen or some where in the log I am not able to access it, any advice would be very very appreciated, try it, you will have a detail property and try to write them on the screen or some where to persist, you will not find it in the code to write it.
|
|
|
|
|
The Exception class doesn't have a Details property, so you're code can't see it. You're basically casting the exception object back up to the root Exception class, stripping all the properties that don't exist in the Exception class.
If you want to catch a specific type of exception, you have to put that type in the catch statement:
try
{
}
catch (SomeSpecificExceptionClass ex)
The QuickWatch window uses the actual type of the class to fill in all available properties. That's why you see it in QuickWatch but the code can't.
|
|
|
|
|
Anyways to bring that up into the code of the catch block?
|
|
|
|
|
Change your exception handler to the type shown in the quick watch.
This space for rent
|
|
|
|
|
|
Yes thanks my friend, just trying to get work around if any, since the Inner Exception and Message properties both are coming null from the Service.
Yeah I agree, you did give me idea what it is actually and thank you very much for the help.
|
|
|
|
|
|
Yeah I understand that, but I am seeing the Detail property in the Quick-watch but not in the intellisense and while trying to code the values, just try it, you can understand, I don't know why is it happening.
|
|
|
|
|
You just need to change your code to display all the information that the exception provides. As I said previously, look at the documentation for what is available.
|
|
|
|
|
|
I have 2 .net forms, each with their own BindingSource which I set to go after the same DataTable. The table is filled early on with 35 rows. One of the BindingSources has a filter set when the form loads, which makes the result set 4 rows. When I go back to the first form, the row count has gone down to 4 - if I set that BindingSource filter to "", the count returns to 35.
It looks as if the two binding sources are sharing stuff, where changing the filter on one affects the other.
Any explanation for this? I am working around it but would like to understand the mechanism.
Bob
|
|
|
|
|