Application Insight in MVC and testing from another C# Test project - azure-application-insights

I have a MVC application the application insight is working fine from that application. ,We have a test C# class project, from there i am invoking a method which is having the code to trigger the application insight event, but it is throwing following error.,
Type 'Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector' could not be loaded
I copied the MVC applicationInsight.cofig file into the C# test web project and added entries in the
<httpmodules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpmodules>
Application 1 -> Testproject C# Class project
{
Appinsight a = new Appinsight();
a.Function1();
}
MVC WebApplication
Class Appinsight
{
Funciton1()
{
TelemetryClient o = new TelemetryClient();
}
}

if it can't load assemblies, that means that when your test project runs, some of the app insights classes couldn't be found. you need to make sure that wherever your test code is running from, that all of the same assemblies that are deployed to the website are also deployed to wherever the test code is running from.

Related

How to resolve %DNX_PATH% in development environment?

I have a partially developed ASP.NET 5 application. The application has the following three sub projects:
Web
Web.API
Auth.Server
The Web project relies on the Auth.Server for the OAuth implementation and redirects to that project on load. There's some configuration related to the httpPlatform handler in the Web project's web.config.
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
This throws a Bad Gateway error related to the httpPlatformHandler when I run or view in browser the Web project from VS2015. However I've tried publishing the site locally and hosting in IIS with httpPlatformHandler (version 1.2) installed on IIS which actually works.
I could see that this creates an approot folder with a web.cmd file that has %DNX_PATH% variable defined and that the web.config in wwwroot refers this particular approot/web.cmd file for the processPath attribute.
Question: What location should I point the processPath in the development environment?
I'm new to ASP.NET 5 and only have some basic reading under my belt.

WCF Deployment on windows server 2012

I have made an WCF service application and a MVC4 web application.my service uses my web membership provider functions to validate user and my provider uses entity framework to facilitate this validation.Locally when I run multiple projects as starup and use my application with services, it works perfectly.Now I have deployed this web service on windows 2012 server following these steps :
Enable Wcf on windows server 2012.But the problem is that I am getting the following error:
Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I have even added system.web.razor in my references of web service but still the problem is there. Any help would be appreciated.
Right click on System.Web.WebPages and select properties. Set Copy local to true. Then publish again and the dll will be copied to the bin folder of the target.

Web.config configuration when using separate Project for logging Log4Net

I have a Visual Studio solution with 2 proyects:
Web Application
Library project for logging
My Web Application project doesn't have Log4Net reference. The Logging Project is the one that has the reference to the Log4Net dll and it has a Manager Class where I have all the methods for logging.
Now, I want to know what do I have to do in the Web Application WEb.Config file, I saw on the internet that I have to add a Section:
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net"/>
But my concern is that my web project doesn't have the Log4Net dll reference. Is there I way I can do that without adding Log4Net dll to my web project?
Yes, you can add the section element for log4net without referencing log4net.dll in your web application project.
To be sure, I double checked this with a scratch web application project (WebApplication1) and class library (ClassLibrary1) targeting .NET 4.0 in Visual Studio 2013. ClassLibrary1 referenced log4net.dll, but WebApplication1 did not; it just referenced ClassLibrary1 and had a log4net section element & related log4net element in its Web.config: logging to a text file via log4net worked beautifully.
It seems you have forgotten to configure log4net. Best practice is to add a configure attribute in your assably.cs:
// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
// Configure log4net using the .log4net file
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.ex
You can add the attribute in your log4net dll, there is no need for a reference to log4net in you web project.

app_code find assemblyqualifiedname of class

I have been following Scott Gutheries Blog on how to auto start an ASP.Net application and have an issue with assembly names.
Firstly the web site that I have been following is:
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
I have added the following code to my applicationHost config file, and as you may have guessed it does not work because of the type definition.
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="MyWebSiteName.PreWarmCache, MyWebSiteName" />
</serviceAutoStartProviders>
I have hunted around for a solution and came across this neat code.
Dim _a as New MyApp.PreWarmCache()
_a.GetType().AssemblyQualifiedName
This produces the following result.
"MyApp.PreWarmCache, App_Code.<#########>, Version=0.0.0.0, Culture=neutral, PublickKeyToken=null"
My problem comes from the ######### in the above assembly name as it is unique each time it is run and therefore I cannot use it in the applicationHost file above.
Is there a way to get that value fixed, so the value becomes fixed and does not change?
If you want control over the assembly name and version number that is generated for the site you should use a Web Application Projects instead of a Web Site Projects in Visual Studio.
You could read about the two types of projects on msdn : Web Application Projects versus Web Site Projects in Visual Studio.
With an application project the assembly name doesn't change for each build and you can easily reference the assembly.
To migrate from one type of project to another you will find advices here : Converting a Web Site Project to a Web Application Project
Add a new Class Library project to your ASP.NET website solution and call it Startup.
Create a new class in this library called "ApplicationPreload" that implements IProcessHostPreloadClient.
Add your new Startup class library as a Reference in your ASP.NET Website
Compile your Solution which will add Startup.dll to your website's Bin directory
Add the following to your applicationHost.config file right under the </sites> section
<serviceAutoStartProviders>
<add name="ApplicationPreload" type="Startup.ApplicationPreload, Startup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /
</serviceAutoStartProviders>

Not able to load Microsoft.Http dll in ASP.NET MVC3 application at runtime

I created a WCF service and exposed it as REST service. I am trying to consume this service from ASP.Net MVC3 application.
I added a reference to Microsoft.Http dll, to use HttpClient and get the response from a POST method of REST service, as in the code below -
string uri = http://localhost:12958/Host1/RestService.svc/SubmitAdvisor;
using (HttpResponseMessage response = new HttpClient().Post(uri, HttpContentExtensions.CreateDataContract(obj)))
{
};
I get the follwing error at runtime -
Could not load file or assembly 'Microsoft.Http, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What is it I am missing?
Download from this link http://aspnet.codeplex.com/releases/view/24644
After,
Microsoft.Http.dll's location is like this
C:\Program Files (x86)\Microsoft WCF REST\WCF REST Starter Kit Preview
2\Assemblies

Resources