Unable to trigger a Snapshot Debugger snapshot from code - azure-application-insights

This is in a Visual Studio Solution with an Asp.Net MVC app targeting .NET Framework 4.6 as the UI project, and several other C# class library projects.
We Application Insights Nuget packages, including the Snapshot Collector package, to all the projects in the solution we wish to trace. All Nuget packages use the latest version.
To trigger a snapshot from code, I throw an exception like so:
try
{
throw new Exception("This is an AI test exception");
}
catch (Exception ex)
{
var ai = new TelemetryClient();
var props = new Dictionary<string, string> { { "Property1", "A test property value" } };
ai.TrackException(ex, props);
}
The MVC Project's ApplicationInsights.config is configured as follows
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector">
<IsEnabledInDeveloperMode>false</IsEnabledInDeveloperMode>
<HandleUntrackedExceptions>true</HandleUntrackedExceptions>
<ThresholdForSnapshotting>1</ThresholdForSnapshotting>
<ProblemCounterResetInterval>2.00:00:00</ProblemCounterResetInterval> <!--2 days-->
</Add>
</TelemetryProcessors>
I published the app to Azure and invoked the exception several times by browsing the App.
This setup results in the exception being recorded to Application Insights, but without the snapshot. Snapshots work fine for unhandled exceptions.
Shouldn't it take a snapshot after the exception occurs a second time?

Please try the following steps:
1) change your IsEnabledInDeveloperMode to true in ApplicationInsights.config file.
true means that it will enable Snapshot Debugging.
<IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>
2) add this before your code to check if there is an error loading the assembly.
var _ = typeof(SnapshotCollectorTelemetryProcessor);
3) add bindredirect in your web.config file:
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="xxxxx" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.15.0.44797" newVersion="2.15.0.44797"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights.SnapshotCollector" publicKeyToken="xxxx" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.7.0" newVersion="1.3.7.0" />
</dependentAssembly>
Usually, the activities will be in the %temp% folder.
If these do not work,
a) disable any vs installed extensions under Extensions-->Manage Extensions
b) reset vs settings under Tools-->Import and Export Settings--> Reset all settings
c) delete .vs hidden folder, bin and obj folder.

Related

Newtonsoft.json dll issue in ssis

Can anybody help to resolve this.
I have added third party reference (Json newtonsoft) dll in my script component, but when i run the package through sql server agent, I am getting an error
Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
I have registered the dll in gac and same dll (even same version) is also used in uat but while executing on prod it is getting failed.
Any suggestions?
Firstly I would check that the version in the web.config matches the version of the DLL. Right click on the newstonsoft.dll and go to details tab, product version.
You should then have a corresponding assembly identity in your web.config like
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0"
newVersion="10.0.0.0" />
</dependentAssembly>
Also if you have multiple projects in your solution then right click your solution, manage nuget packages for solution and go to the consolidate tab to check that you don't have multiple versions of newtonsoft
Finally resolved the issue-
The command to register DLL was having space before the DLL name. While registering through cmd it showed registering success however the folder was not created in gac_msil location I. E. dll was not registered.

Could not load file or assembly 'App_Code' or one of its dependencies.

Problem: I want to deploy modified code into web server. web server is having IIS version set to V2.0. and now I have developed and published code on my local machine with version 4.0. (there is App_code.dll as part of all dll files).
Now whenever I am deploying all files along with App_code.dll I am getting following error:"
Could not load file or assembly 'App_Code' or one of its dependencies.
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
1) My question is how do I build App_code.dll in older version.
2) I tried changing target framework to V2.0 while publishing but then its not working because AJAX functions from other dll are not compiling..
can anyone please suggest what to do to run the site..
Help is appreciated.
Thanks
Sorry about the answers I've given... But try this...
Try adding <codeBase> elements to the application config file to specify the exact location of each dll, and the version of .Net it requires. Apparently this works because <codebase> is checked BEFORE the probing heuristics kick in each time an assembly needs to be loaded.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="sharedlibA" culture="neutral" publicKeyToken="..." />
<codeBase version="1.0.0.0" href="bin\sharedlibA.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="sharedlibB" culture="neutral" publicKeyToken="..." />
<codeBase version="1.0.0.0" href="bin\sharedlibB.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
If that doesn't work try this.
Late answer but, I'm writing this for future viewers.
I had same error after publish the application to the Server.
I figure it out doing like this.
While publish there is configuration in Setting.
In publish section there is option called
Precompile during publishing
you have to check the checkbox and save then Publish. This will takes your code files .vb/.cs and converts them into a compiled DLL files.
In my case it was unchecked.

Microsoft.SqlServer.Types with Service Fabric

Problem is pretty simple. I moved a WebApps project to Service Fabric which had the Microsoft.SqlServer.Types nuget package installed. Now, when trying to access database I'm getting the following error because I'm using spatial types.
"Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. "
I've tried adding the following line of code to the class which the FabricRuntime creates an instance of, but that was of no use.
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Your help would be appreciated, please do let me know if you need more info from me.
You do need the line of code, but for asp.net application it should be slightly different:
For Asp.net websites, Default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
static bool _isSqlTypesLoaded = false;
public _Default()
{
if (!_isSqlTypesLoaded)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
_isSqlTypesLoaded = true;
}
}
}
For web applications, in Global.asax.cs:
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
Also you need to create the following binding redirect in web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Here is the only discussion on the topic which helped me.
Update: Here is a blog post that provides a well described solution in 3 steps. Although, the third step didn't work for me and I had to create the binding as described above.

Assembly Reference Catch-22

I'm trying to integrate MangoChat into an existing .Net project. Mango requires the use of Newtonsoft.Json version 3.5.0.0, however my current version of this assembly is 6.x.
Logically, I thought to uninstall the current version but it has so many dependencies that it tears apart the project. I can't install version 3.5.0.0 beside 6.x because I can't add a second assembly to the .bin folder with the same name.
How could I solve this issue?
If version 6.x is compatible with version 3.5.0.0, you can add a binding redirect to new version. You should add it to your configuration file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="[enter token here]" culture="neutral" />
<bindingRedirect oldVersion="3.5.0.0-6.X" newVersion="6.X"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Replace 6.X with your actual version.
Another option is to add assembly to different folder and use AssemblyResolve event on AppDomain to find it. You can use such code:
//Load assembly from alternative location
Assembly newtonsoftAssembly = Assembly.LoadFrom(#"C:\PathToYourAssembly.dll");
//Handle AssemblyResolve event
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
//Check if your assembly was requested
if (args.Name.Contains("Newtonsoft.Json"))
{
return newtonsoftAssembly;
}
return null;
};
You should run this code once, e.g. during application startup.

Cannot get ServiceStack.OrmLite.Sqlite64 example working

I am running under .NET 4.5 with VS 2012 Desktop Express. Through NuGet I grabbed ServiceStack and ServiceStack.OrmLite.Sqlite64. I then used the very simple example located http://code.google.com/p/servicestack/wiki/OrmLite to write the following.
class Program {
static void Main(string[] args) {
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
using (IDbConnection db = #"C:\test.s3db".OpenDbConnection()) {
db.CreateTable<Example>(true);
db.Insert(new Example { Id = 1, Text = "An example" });
var items = db.Select<Example>();
items.ForEach(x => Console.WriteLine(x.Id + "\t" + x.Text));
}
}
}
public class Example {
public int Id { get; set; }
public string Text { get; set; }
}
The code above compiles however I get a run time exception that seems to indicate that I am using a System.Data.Sqlite version that differs from what ServiceStack.OrmLite.SqliteNET was compiled against. The version provided to me by NuGet was 1.0.81.0 while the runtime exception appears to be looking for version 1.0.65.0.
I am new to using NuGet so I may have done something wrong, however I have been unable to determine what it is that I have done incorrectly. Assistance would be appreciated.
I noticed that the NuGet package ServiceStack.OrmLite.Sqlite64 was updated today. After installing the newest package the example worked as intended. It appears to have been an incorrect version of System.Data.Sqlite being supplied by the package that was causing my issue.
I've had this exact same experience with ServiceStack and SQLite, which occurred when the SQLite version listed as a dependency for ServiceStack.OrmLite.Sqlite* (via packages.config) was no longer available on NuGet (since the SQLite folks seem to remove old versions when they add new ones). I've submitted past pull requests to ServiceStack to keep this updated, but was also able to solve it locally with an assembly binding redirect:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite"
publicKeyToken="db937bc2d44ff139"
culture="neutral" />
<bindingRedirect oldVersion="1.0.82.0" newVersion="1.0.84.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The above, in an App.config file, let my unit test assembly redirect ServiceStack's runtime binding request for SQLite 1.0.82 (which it was expecting) to 1.0.84 (which was the version available on NuGet), and thus it ran without error even though 1.0.84 was the only version available on my system.

Resources