I would like to profile my application, and check if any part of my code is using reflection, but also if any part of the dotnet core or netstandard framework is using reflection during my application execution and usage.
The purpose of this exercise is to eventually detect reflexion usage at build time, at least reflection that is not put in a cache, but also try to improve the global performances of my webapi.
Thank you
Related
As I know Microsoft.Owin.Host.SystemWeb allows me to run OWIN app on IIS, but today I found another package called Microsoft.Owin.Host.IIS that (as I understand from it's name) has similar purpose.
Actually I think that I am wrong and that packages are very different.
So, here the questions:
What is the difference between that two packages?
In what case should I use one or another?
And last (optional): can someone give me a link to good explanation of all that ASP.NET 5 mess? (Microsoft creates new platforms/frameworks/features faster than document them, so I am feeling quite disoriented now...)
To answer your optional question:
The problem with System.Web is that it is way too bloated and coupled with IIS. As an example, you cannot host an MVC website in a Console Window. You are forced to run it in IIS. The OWIN initiative is an attempt to modularize and decouple the Web Stack by adding abstraction.
In essence, the entire Web Stack is reduced to a pipeline of middleware components (similar to the way node.js does things). A middleware component or AppFunc (Func<IDictionary<string, object>,Task>) is a function that takes a context (containing request, response and other things...) and does something with it (request parsing, routing, rendering a view, logging stuff, ...). The entire stack then becomes a sequence of middleware components: every component calls the next one in the chain, or breaks execution by not calling the next one.
ASP.NET 5 is a natural evolution in the sense that it builds upon OWIN and as such enables modularity and removes the dependency on System.Web (and IIS). Everything is now opt-in and you can even run applications cross-platform (using .NET Core). This would never be possible without OWIN.
Microsoft creates new platforms/frameworks/features faster than document them
The concurrent development of MVC 6, Katana (OWIN) and ASP.NET 6 isn't really helping to clear the confusion between all that's going on.
As far as I understand it:
The Microsoft.Owin.Host.IIS namespace, assembly and package are for Helios, introduced in this blog post. Basically it's meant to run managed code, without ASP.NET, in IIS - to provide your own OWIN middleware on top of that.
So you seem to need Microsoft.Owin.Host.SystemWeb for your purposes. This forms an OWIN host that allows your middleware to use System.Web.
I have an existing application that is closed-source and ships its own version of Mono 3.5. I want to change the behavior of the application; specifically, I want to swap out a built-in class with a new one.
Normally, one goes about this with Mono.Cecil. However, in my case the application assembly is loaded from a readonly volume which makes modifying the assembly itself very very tricky (it involves hardware hacks to produce a new volume). I can, however, get it to load an arbitrary DLL via an officially-supported mechanism, which I could in theory use to modify the assembly at runtime.
There are numerous resources for achieving runtime code injection / function hooking via the .NET Framework, but they all fail under Mono. Approaches I've seen include:
System.Reflection.Emit.MethodRental.SwapMethodBody - not implemented in Mono
This CodeProject sample - uses Microsoft internals
Microsoft Fakes - more Microsoft internals
This MSDN blog post - Even more Microsoft internals
See related questions:
Can Mono.Cecil modify code already loaded in the AppDomain?
Can I redirect .NET method calls to a new method at runtime?
Dynamically replace the contents of a C# method?
I am aware that this is a pretty terrible plan. However since I don't have the sourcecode and modifying the assembly on disk is even more terrible than doing some kind of dirty runtime hack, this is the best alternative I've generated so far.
I'm using Caliburn micro with a WinRT application and it looks like that there's no StorageManager class, anyone has suggestions about how to persist application/ViewModels state in this case.
TIA
This is not related to Caliburn.Micro but rather a general issue. You can either use Serialization but then you will have to pay attention to versioning and changes in your view model or you could save the fields you are interested in to a file using the normal IO methods or even store your view models in the database if you wish (although i think this might be a bit extreme).
Edit: Caliburn.Micro isn't a business application framework and there have been no library that tried to integrate business functionality with CM as far as i know, so this leaves you with serialization as your best option but as i said ser/des comes with some nightmares you have to manage such as version changes, class changes, etc.
There's another project called Catel which is a business application framework that contains an MVVM framework, anyway Catel uses a nice object called DataObjectBase ( actually now it is called ModelBase) which solves all problems of serialization and there is an article for that on code project if you want to read it and see how they have done it.
If you wish you can use the Catel.Core module which is a library with a lot of features for data handling (it contains the ModelBase class) or you can take a look at the source code and see how they have solved the issue with ser/des and implement that with Caliburn.Micro in your project.
I'm porting a cpu-heavy .net 4.0 windows application to a .net 4.0 wcf service. Basically I just imported the .net classes to the wcf service.
All is working well except for performance at the wcf service - a task that takes 6267947 ticks (2539ms) uses 815349861 ticks (13045ms) on the aspx.net wcf service running locally on the same develop machine.
I allready have uploaded the service + a test client to appharbor where the performance is as bad as on my local machine - the link to my test app is: http://www.wsolver.com/. Any ideas on how I can improve performance?
Check any dependencies on your service that may be constructed at Request Time. These Include constructor dependencies and field/property dependencies. Maybe one of them is causing the delay? If this is the case consider using a singleton to instantiate the long running class.
Have you confirmed that subsequent requests still cause the delay?
Also create a band new service that does something simple like Datetime.Now.toString() and see if it has the same problem.
Please take a look at the articles and whitepapers below. I think they should give you enough concrete performance considerations to explore, and likely some very practical settings to tweak, optimize, or change.
Performance Tuning WCF Services
Optimizing WCF Web Service Performance
Using ServiceThrottlingBehavior to Control WCF Service Performance
Transport Quotas
Optimizing IIS Performance
ASP.NET Performance Overview
A Performance Comparison of Windows Communication Foundation (WCF) with Existing Distributed Communication Technologies
If you need to do time-consuming initialization of a complex datastructure, you should to that once in Application_Start() and assign the generated datastructure to a static variable on the MvcApplication object. Doing it just once on application start is going to be much faster that doing it in each request.
I would take a full memory dump during the 13 seconds (or several using procdump) and then acutally look at what is occurring in the process (windbg and sos.dll). Then, you can narrow down which code is the culprit.
I take it that the dictionary tree is only loaded once, into cache? You're not loading it on every call are you?
The question in short is that we are stumbling upon BDD definitions that more or less require different states - which leads to the necessity for a mock of sorts for ASP.NET/MVC - I know of none, which is why I ask here
Details:
We are developing a project in ASP.NET (MVC3/Razor engine) and are using SpecFlow to drive our development.
We quite often stumble into situations where we need the webpage under test to perform in a certain manner so that we can verify the behavior, i.e:
Scenario: Should render alternatively when backend system is down
Given that the backend system is down
And there are no channels for the page to display
When I inspect the webpage under test
Then the page renderes an alternative html indicating that there is a problem
For a unit test, this is less of an issue - run mock on the controller bit, and verify that it delivers the correct results, however, for a SpecFlow test, this is more or less requiring alternate configurations.
So it is possible at all, or - are there some known software patterns for developing webpages using BDD that I've missed?
Even when using SpecFlow, you can still use a mocking framework. What I would do is use the [BeforeScenario] attribute to set up the mocks for the test e.g.
[BeforeScenario]
public void BeforeShouldRenderAlternatively()
{
// Do mock setups.
}
This SO question might come in handy for you also.
You could use Deleporter
Deleporter is a little .NET library that teleports arbitrary delegates into an ASP.NET application in some other process (e.g., hosted in IIS) and runs them there.
It lets you delve into a remote ASP.NET application’s internals without any special cooperation from the remote app, and then you can do any of the following:
Cross-process mocking, by combining it with any mocking tool. For example, you could inject a temporary mock database or simulate the passing of time (e.g., if your integration tests want to specify what happens after 30 days or whatever)
Test different configurations, by writing to static properties in the remote ASP.NET appdomain or using the ConfigurationManager API to edit its entries.
Run teardown or cleanup logic such as flushing caches. For example, recently I needed to restore a SQL database to a known state after each test in the suite. The trouble was that ASP.NET connection pool was still holding open connections on the old database, causing connection errors. I resolved this easily by using Deleporter to issue a SqlConnection.ClearAllPools() command in the remote appdomain – the ASP.NET app under test didn’t need to know anything about it.