»
S
I
D
E
B
A
R
«
Could not load type System.ServiceModel.Activation.HttpModule
Jan 26th, 2012 by evereq

Get following exception during first load of ASP.NET MVC 4 site in IIS7.5 under Window 2008 R2:

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.

Easy to fix using following command (run as administrator):
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -iru

Done :)

P.S. if for some strange reason you still use 32 bit Windows, you should update framework path in command above.

HTTP Error 403.14 – Forbidden fix
Jan 26th, 2012 by evereq

You just setup new Windows 2008 R2 Server, enable IIS role, install ASP.NET MVC 1/2/3 or 4, upload your site, configure IIS (i.e. IIS pool, rights, certificates etc) and get following error in browser:

HTTP Error 403.14 – Forbidden
The Web server is configured to not list the contents of this directory.

Hm… EASY to fix with following command (run command prompt as administrator!):
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i

Done :)

P.S. if for some strange reason you still use 32 bit Windows, you should update framework path in command above.

ASP.NET Session state system everytime returns different values for SessionID
Dec 12th, 2011 by evereq

Suppose you have ASP.NET (or ASP.NET MVC) site.
You want to use Session.SessionID value somewhere (say as shopping cart id), which normally should be SAME value for each request from the same browser (sure unless session expire or user clean cookies, or you forget to store session in some distributed storage and use Web Farm with multiple front-end servers, or you forget to … actually many things might be here).
However you may see every time DIFFERENT value for Session.SessionID for anonymous user!
How? Reason: new SessionID is generated by ASP.NET, UNLESS YOU STORE SOMETHING IN THE SESSION!
For example do something like this: Session["Something"] = 1 after first user request and you will see that SessionID remains unchanged.
Sounds crazy, right???

.NET performance and your hardware
Apr 14th, 2011 by evereq

Was inspired by Ayende post (see http://ayende.com/Blog/archive/2011/04/14/performance-numbers-in-the-pub.aspx) and want to check how much objects my work PC may create :D
Moreover, now seems best time to do that – my company order today new SUPER machines for our team, so it will be interesting to see difference with current PC using such “.NET” test.

My current PC is Intel Q8200 4 Cores / 8Gb memory / SSD Intel 80Gb etc – you get idea :)

Main difference between my code and Ayende code (as well as many blog comments code) is that I create objects using multiple threads. What is interesting for me that most of people even today, just forget the fact that they have multiple cores in PC (or Server) and modern development should be done with that “stick” idea in your mind: “multitask / multithreading / async may be used if you want to utilize optimally your hardware”. Sure it’s not always make sense to go that “hard way” – some tasks just not scale too much with that approach. At the same time, in that specific tests I was able to get about 50% performance gain using very simple threading model compared to the single threaded. Not bad enough, right?

Sure it’s not really optimal strategy (more optimal for sure to just use C / C++) and I think memory speed restrict CPU power in that specific tests (i.e. no matter how many cores you use in CPU, if your memory / memory controller just can’t get / process all that in the parallel).  In addition I also initialize each created object integer field with some value to restrict some possible optimizations in CLI.  You can also found multiple small optimizations to avoid some overhead etc. Sure it’s not best code out there, but effective enough to demonstrate how TPL can improve results even in such a simple task. Maybe later will found time and write same using C++ with Parallel Patterns Library (PPL) to measure the difference :D

On my PC test create 4 new threads and each thread create multiple objects. Note that test works 10 seconds to give you more precise results :)

Tests results: around 150M created and initialized objects per second (don’t forget to build in Release mode if you really want to run it)
I promise to publish new results when new PC arrive to our office;-)

Btw, if you get your own results, will be glad to see and compare :D

Stay tuned :)

P.S. Code is not finally optimized and is not “production ready”. Means that I just want to play a bit with what Ayende originally wrote…
For example, you probably may note that test will take longer than 10 seconds to run if your PC already busy with some tasks (simply because I use too much threads for such environment) etc.

P.P.S. No warranties :) Please do not run that code on your production servers :D

Update #1: My colleague have notebook with Intel i5 CPU (4 Cores) and he just get  215M result :D

Update #2: Just get new PC with CPU Intel i7-2600K (at 3.5Ghz) / 8Gb DDR3 1600Mhz memory etc. I get just amazing result: 700M with same source code :D WOW!

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;

namespace Testing
{
    class Program
    {
        static volatile bool _isContinue = true;

        static long _total;

        const int TestTimeSec = 10000;

        static Stopwatch _sp;

        static void Main(string[] args)
        {

            var tasks = new List<Task>();

            int processors = Environment.ProcessorCount;

            Console.WriteLine("Detected {0} cores"processors);

            var timer = new System.Timers.Timer(TestTimeSec);
            timer.Elapsed += TimerElapsed;
            timer.AutoReset = false;
            timer.Start();

            _sp = Stopwatch.StartNew();

            for (int t = 0t < processorst++)
            {
                tasks.Add(Task.Factory.StartNew(
                    () =>
                    {
                        long i = 0;

                        while (_isContinue)
                        {
                            var obj = new MyClass();
                            i++;
                            obj.B = i;
                        }

                        Interlocked.Add(ref _totali);
                    }
                ));
            }

            // let's complete all the tasks to get results into _total
            Task.WaitAll(tasks.ToArray());

            _sp.Stop();

            Console.WriteLine("Created {0} objects in {1}"_total / 10_sp.Elapsed.TotalMilliseconds / 10);
            Console.ReadKey();

        }

        static void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            _isContinue = false;
            Console.WriteLine("Stopping...");
        }

        public class MyClass
        {
            public string A;
            public long B;
            public DateTime C;
        }

    }
}
How to get current application domain directory in .NET
Oct 17th, 2010 by evereq

Few useful ways to get current application domain directory path in .NET
(some for Winforms, some for ASP.NET, some for both):

  • System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
  • AppDomain.CurrentDomain.BaseDirectory
  • Directory.GetCurrentDirectory()
  • Environment.CurrentDirectory
  • this.GetType().Assembly.Location
  • Application.StartupPath
  • HttpContext.Current.Server.MapPath(@”~\”);
  • Application.ExecutablePath
  • HttpContext.Current.Request.PhysicalApplicationPath
»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2008–2010 EvereQ.com All rights reserved. Logos, company names used here if any are only for reference purposes and they may be respective owners right or trademarks.