Skip to content

Instantly share code, notes, and snippets.

@debugthings
debugthings / gist:eaad7b90dbaac294e20b
Created April 7, 2015 00:49
After AsyncResult context fix
xUnit.net ASP.NET test runner (64-bit DNX 4.5.1)
Copyright (C) 2015 Outercurve Foundation.
Discovering: Microsoft.AspNet.TestHost.Tests
Discovered: Microsoft.AspNet.TestHost.Tests
Starting: Microsoft.AspNet.TestHost.Tests
Microsoft.AspNet.TestHost.RequestBuilderTests.AddRequestHeader [FAIL]
System.InvalidCastException : Cannot cast from source type to destination type.
Stack Trace:
at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
@debugthings
debugthings / AsyncResult.cs
Created April 7, 2015 01:05
AsyncResult hack
// REMOVED Xamarin LICENSE FOR BREVITY PLEASE SEE THE FOLLOWING LINK
// https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/corlib/System.Runtime.Remoting.Messaging/AsyncResult.cs
using System;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting.Messaging
{
@debugthings
debugthings / StackTrace
Created April 7, 2015 04:05
Mono/xUnit/ASPNET5 Stack
Microsoft.AspNet.TestHost.TestClientTests.GetAsyncWorks [FAIL]
System.NullReferenceException : Object reference not set to an instance of an object
Stack Trace:
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService (IServiceProvider provider, System.Type serviceType) [0x00000] in <filename unknown>:0
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[IServiceManifest] (IServiceProvider provider) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Hosting.Internal.RootHostingServiceCollectionInitializer.Build () [0x00007] in <filename unknown>:0
at Microsoft.AspNet.Hosting.WebHost.CreateFactory (IServiceProvider fallbackServices, System.Action`1 configureServices) [0x00012] in <filename unknown>:0
at Microsoft.AspNet.Hosting.WebHost.CreateEngine (IServiceProvider fallbackServices, IConfiguration config, System.Action`1 configureServices) [0x00001] in <filename unknown>:0
@debugthings
debugthings / AsyncPost
Created April 9, 2015 04:29
Stack Trace AsyncResult
"<unnamed thread>" tid=0x0x7fffee397700 this=0x0x7ffff4edeed0 thread handle 0x43f state : not waiting owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_debugger_agent_user_break () <IL 0x0000c, 0xffffffff>
at System.Runtime.Remoting.Messaging.AsyncResult..ctor (System.Threading.WaitCallback,object,bool) [0x00014] in /home/jldgit/mono/mcs/class/corlib/System.Runtime.Remoting.Messaging/AsyncResult.cs:74
at System.Threading.ThreadPool.QueueWorkItem (System.Threading.WaitCallback,object) [0x00000] in /home/jldgit/mono/mcs/class/corlib/System.Threading/ThreadPool.cs:102
at System.Threading.Tasks.TpScheduler.QueueTask (System.Threading.Tasks.Task) [0x00041] in /home/jldgit/mono/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs:53
at System.Threading.Tasks.Task.Schedule (bool) [0x00007] in /home/jldgit/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:395
at System.Threading.Tasks.Task.Start (System.Threading.Tasks.TaskScheduler) [0x0005b] in /home/jld
@debugthings
debugthings / GetSOAPActionInitializer.cs
Created September 2, 2016 15:51
Custom Telemetry Initializer that Gets the SOAP Action
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CustomTelemetryInitializer
{
public class GetSOAPActionInitializer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
@debugthings
debugthings / CaptureStream.cs
Created September 8, 2016 20:36
Part of a solution to capture the response of a web request.
using System;
using System.IO;
using System.Text;
public class CaptureStream : Stream
{
private Stream ResponseStream = null;
private int len = 0;
private StringBuilder sb;
public class IPAddressTelemetryInitializer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry)
{
var telem = telemetry as Microsoft.ApplicationInsights.DataContracts.RequestTelemetry;
var ip = System.Web.HttpContext.Current.Request.UserHostAddress;
telem.Properties.Add("IP", ip);
}
@debugthings
debugthings / ApplicationInsights.config
Created October 13, 2016 02:16
Instant Read Alert Rule
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<TelemetryProcessors>
<Add Type="SFLCC.InstantReadProcessor, SFLCC">
<RequestDurationToTriggerOnInMilliseconds>5000</RequestDurationToTriggerOnInMilliseconds>
<TimeToStayTriggeredInSeconds>60</TimeToStayTriggeredInSeconds>
</Add>
</TelemetryProcessors>
</ApplicationInsights>
@debugthings
debugthings / NoArgumentExceptionsFilter.cs
Created October 20, 2016 18:59
No Argument Exceptions Filter
public class NoArgumentExceptionsFilter : Microsoft.ApplicationInsights.Extensibility.ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
private bool parsed = false;
public string ExceptionToFilter { get; set; }
public NoArgumentExceptionsFilter(ITelemetryProcessor next)
{
this.Next = next;
}
@debugthings
debugthings / GetBrowserOnServer.cs
Created December 28, 2016 17:43
Set Browser on Server Side Telemetry
public class GetBrowserOnServer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
try
{
if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry)
{
var telem = telemetry as Microsoft.ApplicationInsights.DataContracts.RequestTelemetry;
if (System.Web.HttpContext.Current.Request.Browser != null)