Click here to Skip to main content
14,237,418 members

.NET Framework

 
GeneralRe: WPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace1-Mar-19 9:11
memberSaved By Grace1-Mar-19 9:11 
SuggestionRe: WPF DataGridComboBoxColumn Binding Issue Pin
FLYFLU20-Mar-19 15:30
memberFLYFLU20-Mar-19 15:30 
QuestionCOM Interop with latest .NET Framework Pin
JackMisani19-Feb-19 0:19
memberJackMisani19-Feb-19 0:19 
AnswerRe: COM Interop with latest .NET Framework Pin
Gerry Schmitz19-Feb-19 5:54
mveGerry Schmitz19-Feb-19 5:54 
GeneralRe: COM Interop with latest .NET Framework Pin
JackMisani19-Feb-19 6:29
memberJackMisani19-Feb-19 6:29 
QuestionMSIL: Are there practical uses for writing MSIL code that can't be done in C# Pin
nrnoble18-Feb-19 0:29
membernrnoble18-Feb-19 0:29 
AnswerRe: MSIL: Are there practical uses for writing MSIL code that can't be done in C# Pin
Richard Deeming18-Feb-19 1:19
mveRichard Deeming18-Feb-19 1:19 
QuestionTask based asyn Pin
anilkumar198612-Feb-19 18:50
memberanilkumar198612-Feb-19 18:50 
HI Freinds,

In our Project we are changing some methods synchronous to asynchronous.There is one situation iam using task.run concept we have global error log where we can read entire structure of the error.when i apply task.run global error log is broken.

Here is my code:
try{
Task.Run(() =>
{

SendMailForGSSCQuotes(mDBEntity.QUOTATIONNUMBER.ToString(), Convert.ToInt32(mDBEntity.ThresholdQty), Convert.ToInt32(mDBEntity.ISHAZARDOUSCARGO), Convert.ToInt32(mDBEntity.HASMISSINGCHARGES));
}).ConfigureAwait(false);
}
catch(Exception ex){
LogErrorAsync("api/Quotation", "SendMail", ex.Message.ToString(), ex.StackTrace.ToString());

}

in SendMailForGSSCQuotes intentionally throwing error to see how the global error log works.


protected void LogErrorAsync(string controller, string action, string message, string stacktrace, string user = "")
     {
         QuotationDBFactory mFactory = new QuotationDBFactory();
         mFactory.InsertErrorLog(
             user,
             controller,
             action,
             message,
             stacktrace
          );
         SendEmailAysnc(stacktrace, message).ConfigureAwait(false);
     }
     internal async Task<bool> SendEmailAysnc(string st, string ex)
     {
         try
         {
             var Content = string.Empty;
             if (this.ActionContext.Request.Method.ToString() == "POST")
             {
                 var d = new StreamReader(await Task.Run(() => this.ActionContext.Request.Content.ReadAsStreamAsync().Result).ConfigureAwait(true));
                 d.BaseStream.Seek(0, SeekOrigin.Begin);
                 Content = d.ReadToEnd();
             }
             var hostdata = ((System.Web.HttpRequestWrapper)this.RequestContext.GetType().Assembly.GetType("System.Web.Http.WebHost.WebHostHttpRequestContext").GetProperty("WebRequest").GetMethod.Invoke(this.RequestContext, null));
             var exdata = new ExceptionEmailDto()
             {
                 ActionMethod = this.ActionContext.Request.Method.ToString(),
                 AppUrl = System.Configuration.ConfigurationManager.AppSettings["APPURL"],
                 Error = ex,
                 Headers = this.ActionContext.Request.Headers.ToString(),
                 ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"],
                 StackTrace = st,
                 Url = this.ActionContext.Request.RequestUri.ToString(),
                 UserAgent = hostdata.UserAgent == null ? string.Empty : hostdata.UserAgent.ToString(),
                 UserHostAddress = hostdata.UserHostAddress == null ? string.Empty : hostdata.UserHostAddress.ToString(),
                 UserHostName = hostdata.UserHostName == null ? string.Empty : hostdata.UserHostName.ToString(),
                 UTC = DateTime.UtcNow.ToString(),
                 Content = Content,
                 ServerVariables = hostdata.ServerVariables == null ? "undefined" : hostdata.ServerVariables.ToString()
             };
             FOCiS.SSP.Web.UI.Controllers.APIDynamicClass.SendExceptionEmailV2(
                 exdata
             );
         }
         catch (Exception exc)
         {
             FOCiS.SSP.Web.UI.Controllers.APIDynamicClass.SendExceptionEmail(this.ActionContext.Request.Method.ToString(),
                 exc.Message.ToString(), exc.StackTrace.ToString()
             );
             return false;
         }

         return true;
     }


Getting error here

var d = new StreamReader(await Task.Run(() => this.ActionContext.Request.Content.ReadAsStreamAsync().Result).ConfigureAwait(true));


Error:
Cannot access a disposed object.
Object name: 'System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent'.


I tried so many ways if i remove Task.Run its working fine.


Thanks
AnswerRe: Task based asyn Pin
Wastedtalent12-Feb-19 21:21
professionalWastedtalent12-Feb-19 21:21 
GeneralRe: Task based asyn Pin
anilkumar198612-Feb-19 21:37
memberanilkumar198612-Feb-19 21:37 
GeneralRe: Task based asyn Pin
Wastedtalent12-Feb-19 21:48
professionalWastedtalent12-Feb-19 21:48 
GeneralRe: Task based asyn Pin
anilkumar198612-Feb-19 22:52
memberanilkumar198612-Feb-19 22:52 
GeneralRe: Task based asyn Pin
anilkumar198613-Feb-19 1:23
memberanilkumar198613-Feb-19 1:23 
Questionstatement is not valid n a namespace Pin
Member 1384753912-Feb-19 8:07
memberMember 1384753912-Feb-19 8:07 
AnswerRe: statement is not valid n a namespace Pin
Richard Deeming12-Feb-19 10:05
mveRichard Deeming12-Feb-19 10:05 
GeneralRe: statement is not valid n a namespace Pin
Member 1384753913-Feb-19 5:37
memberMember 1384753913-Feb-19 5:37 
QuestionMocking a Service call in my Unit Tests Pin
simpledeveloper8-Feb-19 7:31
membersimpledeveloper8-Feb-19 7:31 
AnswerRe: Mocking a Service call in my Unit Tests Pin
Gerry Schmitz8-Feb-19 10:46
mveGerry Schmitz8-Feb-19 10:46 
GeneralRe: Mocking a Service call in my Unit Tests Pin
simpledeveloper8-Feb-19 10:59
membersimpledeveloper8-Feb-19 10:59 
GeneralRe: Mocking a Service call in my Unit Tests Pin
simpledeveloper11-Feb-19 8:29
membersimpledeveloper11-Feb-19 8:29 
GeneralRe: Mocking a Service call in my Unit Tests Pin
Gerry Schmitz13-Feb-19 5:40
mveGerry Schmitz13-Feb-19 5:40 
QuestionNot able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper4-Feb-19 12:25
membersimpledeveloper4-Feb-19 12:25 
AnswerRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Dave Kreskowiak4-Feb-19 14:04
mveDave Kreskowiak4-Feb-19 14:04 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper8-Feb-19 7:15
membersimpledeveloper8-Feb-19 7:15 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Dave Kreskowiak8-Feb-19 8:49
mveDave Kreskowiak8-Feb-19 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.