JIT compiler and "Method Not Found" error

Filed Under (Development, Misc) by Emad Alashi on 11-08-2009

Tagged Under :

CropperCapture[20]

Actually it can be “Could Not Load Type” too, but the reason is the same: you are referencing the wrong DLL version.

well, this is totally understandable; of course you are going to get this exception when you use an outdated DLL that lacks the new extra parameter to THAT certain method. But the interesting part is it will not happen when you first run your application, and neither when execution reaches the changed method; it will happen when code-execution reaches a place that REFERENCES that changed method.

lets look at the following example.

I have created two projects: Windows Forms project called “HostDLL”, and a Class Library project called “BadDLL”.
The HostDLL references the BadDLL; upon clicking a button in the form, the HostDLL will create an instance of class “BadClass” and call the method “DoStuff” which takes two integer parameters.
everything goes fine:

   20 private void button1_Click(object sender, EventArgs e)

   21         {

   22             BadClass bc = new BadClass();

   23             int x = 3, y = 10;

   24 

   25             bool never = false;

   26             if (never)

   27             {

   28                 bc.DoStuff(x, y);

   29             }

   30             MessageBox.Show(“Done successfully”);

   31         }

Notice the IF clause in line 26, and notice that calling the method “bc.DoStuff” will never take place because the “never” variable is always false.

Now, intentionally, we will make a breaking change in the BadDLL; adding a new integer parameter z to the DoStuff method (we will make this change AFTER we have compiled the HostDLL so we don’t get compile-time correction).

Run the applicaion HostDLL to show the form, you will notice that there is no error, even when the BadDLL has been changed. Now hit the button… you will get a run-time error that says “Method Not Found”. The interesting part of the story is that even though DoStuff will never get called, yet we will still get this run-time error.
The reason is that the JIT compiler does what it’s called after: “Just-In-Time Compiler“; using help from the “CLR via C#” book authored by Jeffery Richter, specifically in “Executing Your Assembly’s Code” section, the explanation is that:

To execute a method, its Intermediate Language must first be converted to native CPU instructions. This is the job of the CLR’s JIT (just-in-time) compiler…Just before the method executes, the CLR detects all of the types that are referenced by the method’s
code (in our case it’s the BadClass). This causes the CLR to allocate an internal data structure that is used to manage access to the referenced types.

The author continues in a graph in which he explains the process:

1. In the assembly that implements the type, look up the method being called in the metadata
2. From the metadata, get the IL for this method
3. Allocate a block of memory
4. Compile the IL into native CPU instructions

So it is at that point the code is compiled, and at that point the JIT discovers that there is a type (which is BadClass in our case) is referenced having an invalid method with one extra parameter.

So always be careful when you reference other DLL’s, if you don’t make sure you have the right version, you will be subject to a potential lovely RTE message :)

“طور نفسك برمجيا”…موجة من عمر قعدان

Filed Under (Development, Misc) by Emad Alashi on 31-07-2009

Tagged Under :

قبل أيام، كتب أخي عمر قعدان في مدونته مقالا بعنوان “شيفرة مصدرية للقراءة” و في آخره استعمل أسلوب “الموجة” في المدونات و هو أسلوب مبتكر في عالم التدوين يقوم صاحبه بكتابة مقال، ثم يطلب في آخر المقال من مدونين معينين كتابة المقال نفسه لكن من تجربتهم الشخصية، و بدورهم يفعلون الأمر ذاته مع آخرين إن أرادوا.
يطلق على هذا الأسلوب في الإنجليزية كلمة “Tagging” و برأيي أن أقرب مرادف لهذا المعنى في اللغة العربية ضمن هذا السياق هو كلمة “موجة”. و ها أنا أستجيب للموجة التي أطلقها أخي عمر.

grow

أفصح عمر في مقالتين له عن كيفية تطوير المبرمج لنفسه، و طلب في موجته الإجابة عن ثلاثة أسئلة:

  • كيف تصقل مهارتك كمبرمج؟
  • ما رأيك بفكرة قراءة الشيفرة المصدرية للتعلم؟
  • و هل هناك برامج مفتوحة المصدر تعلمت منها؟

بالنسبة لي، صقل المهارة يكون: بالتأسيس من خلال القراءة و العلم النظري، و من ثم بالاستكمال في التطبيق العملي. فبدون أي من هذين الجناحين لا أتصور نجاح أي مبرمج أو تقني. فالقراءة و الجانب النظري يثري الجانب العلمي، و التطبيق يأكده؛ إما أن يشكك في صحته و ينفيه، أو يزيد من يقينه.

و إذا ولجنا بتفصيل أكبر في الموضوع، أرى أن في الجناح الأول – و هو الجانب النظري- قد تقيدنا فيه النقاط التالية:

  • بالنسبة للمواضيع الأساسية و القواعد الأولى لأي علم، يكون المصدر الأمثل للمعلومة هو الكتاب المفصل أو المقال الطويل أو المتسلسلات Tutorials (أروعها بالنسبة لي 4guysfromrolla)؛ فلأهميتها لا بد من قراءة متمعنة و عميقة ترسم في الذهن الأبعاد كلها، و تستكمل جميع جوانب الموضوع بتفصيل واسع و دقيق. أمثلة على هذه المواضيع: في عمل البرمجة بالدوت نت “أنواع المتغيرات في الـدوت نت”، في علم البرمجة في مجال الإنترنت “دورة حياة صفحة الـASP.NET” و هلم جر.
  • أما إذا كنت تبحث في علم لست مهتما به كثيرا، أو بعلم يهمك لكن بموضوع يلامسه من بعيد -نسبيا-، فتكون من خلال قراءة المقالات العامة، و التدوينات، و الفيديوهات (أولي بها أهمية أكبر لنجاعتها بتوصيل المعلمومة، و أضيف على عمر فيديوهات ASP.NET)، أو حضور المحاضرات التي تكون بمثابة “مدخل” لهذا العلم.
  • سؤال و متابعة المحترفين؛ مثل متابعة المدونات كمدونة: “سكوت ميتشيل Scott Mitchel” و “سكوت جوثري Scott Guthrie“، أو استخدام تويتر twitter.
  • قراءة “الشيفرة المصدرية” أو الـ Source Code لبرامج أنشأها مبرمجون محترفون في المجتمع، و هي من أهم طرق تحصيل العلم البرمجي؛ فهي مثال حقيقي مجرب بأيدي محترفين ذوي سنوات طويلة من الخبرة، تستطيع من قراءة المصدر أن تفهم كيف يفكر، و متى يستخدم أسلوبا معينا، و كيف يحل معضلة واقعية مشهورة. أمثلة: ASP.NET MVC Nerddinner، RSS.net، و Ninject.
  • تعليم الآخرين و إعطاء المحاضرات أو كتابة المدونات إن أمكن، فلا يزيد ترسيخ المعلومة -بعد التطبيق- أكثر من تعليم الآخرين (و هنا أقول لا تبخل بالمعلومة أبدا أبدا، فالخير العائد إليك أكبر بكثير من ما قد يخطر على بالك من الخسارة إن وجدت)

أما بالنسبة للتطبيق فهو استكمال البناء، فلقد تعلمت من بنيان Bunian أكثير من أي شيء آخر (على الرغم من أنه غير مستكمل لغاية الآن)؛ فإن تابع الشخص كل مدونين التكنولوجيا، و قرأ كتب العظماء، و شاهد جميع الفيديوهات و المتسلسلات، و لم يفتح Visual Studio و طبق ما عرف، فاعلم أنه ليس سوى فقاعة كبيرة -و للأسف-، و سيخونه علمه في أبسط التحديات البرمجية على الطريق.

و أخيرا، من أكثر ما يزيد مهارة الشخص، هو الهمة في التحصيل، و هذه الهمة تزيد أضعافا عند مشاركة الآخرين، سواء في مجتمعات البرمجة الحقيقية (كـ Jordev هنا في الأردن)، أو كالمجتمعات على الإنترنت (كـ www.vb4arab.com). فبمجرد أن تتكلم مع من يشاركك هذا الشغف، لن تتمالك نفسك حتى تعود للمنزل و تفتح الجهاز و تستمع بسماع صوت طرق لوحة المفاتيح :) .

و أمرر هذه الموجة إلى كل من: أحمد أبو عرجة، و طارق سيالة. دون أن يكون هذا على وجه الإلزام.

 

DotNetArabi Episode 3 دوت نت عربي الحلقة الثالثة

Filed Under (Misc) by Emad Alashi on 11-07-2009

 

I just published episode 3 of the DotNetArabi podcast on www.dotnetarabi.com.

This episode was with guest Mahmoud Alamanasrah, who have 7 years of experience on data-driven web applications with SQL Server. The episode was about the new features of SQL Server 2008, great for all developers who interact closely with SQL Server.

على موقع www.dotnetarabi.com تجدون الحلقة الثالثة من “دوت نت عربي”. موضوع الحلقة هو الـ”إس كيو إل سيرفر 2008 SQL Server”، عن آخر المستجدات و بعض النصائح العامة.
كان ضيف الحلقة الزميل محمود المناصرة، و هو عضو نشط في مجتمع مطروي الـ”دوت نت” في الأردن Jordev، لديه 7 سنوات من الخبرة و يعمل حاليا كـ “Technical Team Leader” أي قائد فريق مبرمجين.

Got a GPS? …Lets Play Geocaching

Filed Under (Misc, Personal) by Emad Alashi on 26-06-2009

Tagged Under : , ,

The other day I was roaming the Internet; link here link there, tweet here tweet there, and I stumbled upon a very nice game called Geocaching.
Geocaching, simply, is a game in which players hide items in any place in the world, and the other players should find, yes…Treasure Hunt. But the fun part is it’s Global, and the GPS is your primary tool!

The players who want to hide an item, should first label it and give it a unique identifier, then record the coordinates (longitude and latitude) of the place they hide it in, and finally they should post the information along with the coordinates on the game’s website www.geocaching.com.

And I was lucky enough to know that there are 17 geocaches in Jordan! below is an image of my first geocache quest result with my good friend Tamim Salem, using my iPhone’s GPS.

IMG_0105

IMG_0102 
The item was broken and this paper is the only thing left.

Can’t wait to quest the rest ;)

Technical Team Leader…Who Is Not

Filed Under (Development, Misc, Personal, software management) by Emad Alashi on 24-04-2009

Tagged Under :

image orginially was on "http://www.ccer.org/images/juggle.gif"

When I started this blog my goal was to make it a technical one, in which most posts would have code, samples, screen shots, architecture…etc. This was the primary goal, though it is totally fine with me to talk about software life in general.

The issue is that I get the ideas of my posts from my real daily life, which is mostly code challenges at work. I do write code in my leisure time, but for sure it is not as thorough as the thing at work.
And since I haven’t posted any technical stuff lately…the simple conclusion is I DON’T SEE CODE ANYMORE!

A Technical Team Leader in the place I work at right now has a different meaning from what I knew before; the first word in the title is “Technical” so I expect to deal a lot with code: planning it, reviewing it, discuss it with team members…etc.
But in the environment I work at, there is more pressure toward management and coordination; I find my self during the day doing stuff like updating the Microsoft Project plan, smoke testing, running between other teams we depend on to get their deliverables; checking with the User Experience team if they have the designs ready, checking with the Architecture team if they will pass by to set the folders structure for us…etc. All this leaves me no time to see code.

Is this right? Should a Technical Team Leader do these stuff? If not, who should? Is it a Project Coordinator? what is exactly the job description for a Technical Team Leader?
Questions like these should be discussed with the Development Process people, but till then I will have to say: “that’s not right”.
How about you? what do you think?

Fear and Humbleness…Obstacles in The Way of Success

Filed Under (Development, Misc, Personal) by Emad Alashi on 10-03-2009

“Oh no, I won’t go into that code; I am not that intelligent!”
“oh no, I don’t want to try this software…I don’t know what it will do to my machine!”
“Oh no, I can’t write such a unique blog post!”
“Oh no, I will not twiply to that celebrity…come on…he is a celebrity!”

These phrases kept chasing me for a long while in my life, and sometimes still does. It had the worst effect on my progress, I couldn’t move an inch forward; by a deep feeling I didn’t confront, I was afraid of failure, mixed with a feeling of negative humbleness.
But that was it, I couldn’t stay as a prisoner to these chains, and leave these cookies of success to people who might have less resources and powers.

Then, after realizing this fact and working against it, I am free! within months I have created this blog you are reading, started the open source project Bunian (small but learned a lot from it and in progress), delivered session in JorDev (and still contributing effectively), and preparing a new technical Arabic podcast (to be announced soon).

what helped me to do that:

  • Make backup plans for everything you have paranoia about; backup your drive, use virtual machines, make a dummy blog…etc. This way you will not fear the change, the change which will possibly be the next big thing for you
  • Don’t take it too serious; be cool about it, it’s not going to be the end of the world if it fails. Of course try your best and plan well, but beyond that you only have to take the step and try things out
  • Aim high…but lower your expectations; the higher your expectations are, the more difficult accepting failure is, hence you will not try it out. so lower your expectations and prepare for the failure
  • Try to find more reasons to do it, reasons that will only force you do well without the fear of failure. Joy is an example; I like writing and expressing my feelings/experience in words, so no matter how many subscribers there are, I keep posting to this blog (and no, I am not going to tell you how many, at least not right now :P )
  • Think of all the great stuff you are going to miss because you fear loosing part of what you already have, and sometimes even less. What you are missing could be awesome! and this is not gambling, because you already control the bigger part of it, luck is only a part.
  • Have confidence in your self, because you CAN be better, and the only ones who can’t get better are the ones who DON’T WANT to get better; that is the false modesty.
  • People grow within the limits around them, widen the limits…and see how you will, automatically, grow to fill the space further
  • Don’t be hasty, and grow larger bit by bit…one success leads to another.

These are the things I could think of when it comes to it, I still struggle; it’s a never ending battle with my self, but I hopefully I will not surrender, and I hope this will help others as well.
Finally, we are nothing and can achieve nothing without the help of God; do your best, then ask him for success, that’s the best prescription ever.

Gaza, Starvation For 18 Months And a Massacre Today!

Filed Under (Misc) by Emad Alashi on 27-12-2008

Tagged Under : , , , ,

Update: death toll rate reaches 470 and 2400 injuries, and I will stop counting.

After a 20 months siege during which there was no water, food, medicine, gas, oil, and electricity…today Israel thinks that’s not enough…and starts a massacre; 160 dead, 200 wounded by 40 rockets hit Gaza and still going.

Photos From the Massacre Taking Place Today

English news: here
Arabic news: here

2008122711545599734_2

1_880821_1_34

1_880850_1_34

Photos From the Siege

English news: here
Arabic news: here, and here

26337_11223465084 smuggling food through the tunnels

26337_21223465084 Milk for the small children who lack the basic ingredients for healthy food, finds its only way trough tunnels under ground.

6210x no electricity, you know what this affects; imagine yourself without electricity for 1 week, not saying 20 months!

6130x

610x

Travians be Warned…Rapacious is Rising

Filed Under (Development, Misc, Personal) by Emad Alashi on 12-12-2008

Tagged Under : ,

I don’t know whether thank or scold my good friend Omar Qadan for introducing me to Travian, a strategy game played online.

travian

It’s amazing how a simple,  web-based, HTML-front game can be so rich and vast entertainment wise! It’s a real strategy game where you build villages, resources, armies, embassies, and conduct trading, diplomacy, wars, and alliances…all through simple images, numbers and text.

On the other hand, I can’t ignore the programming part of the game (being a developer that is), it must be big, fun and tiring; think of all these rules and the simulation algorithms the game is being built upon , the server handling thousands of players, …and scripts (yes! lots of hacks!  161 ). Even the hacking idea it self is so delicious (programming wise only  251 ), a true heaven for developers :) .
Also the makers of the game are on the right track of providing developers points through which they can access the game and display information on other sites or applications; ok for now it’s only exporting database tables of statistical information about the game status, but still I consider it a cool step toward supplying nice end-point for developers, maybe Web Services in the future 4.gif .

Every time a new idea hits the web I say “ok, that’s it…there are no more idea’s!”, and every time I say that I  am proved to be wrong; YouTube, Facebook, Wikipedia, Delicous, Digg, SlideShare, Flickr…and the list goes on.
So this is a message for all of us, don’t limit your imagination, ideas never run out.

The only concern now is that I don’t want to be addicted, so let’s wish for the best…and be warned…because Rapacious is rising ;)

Introduction to NHibernate Session at Jordev Was Good

Filed Under (Development, Misc, NHibernate, Personal) by Emad Alashi on 05-12-2008

Tagged Under : , , , ,

The feedback was very good, and I was glad that everybody liked it. Jordev is really moving ahead, and I am very excited being part of it :)

Below is the slide show (it’s an enhanced version from my previous one):

[slideshare id=821222&doc=introductiontonhibernate-1228487480885456-9&w=425]

Code is the same of the previous one which you can download from here

My First Talk at JorDev .net

Filed Under (Development, Misc, NHibernate, Personal) by Emad Alashi on 21-11-2008

Tagged Under : , , , ,

JordevLogo  nhib-logo04

JorDev .net is a .net user group founded by enthusiastic Jordanian IT professionals. On Wednesday the 26th of November I will be doing my first session of a series about NHibernate.
Details of talk is here:

Overview NHibernate is an Object-relational mapping (ORM) solution for the Microsoft .NET platform. it provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.NHibernate is free as open source software that is distributed under the GNU Lesser General Public License
Target Audience .NET Developers, Software Designers, Software Engineers, Software Architects
Date Wednesday, November 26, 2008
Location MIC (Microsoft Innovation Center, Royal Scientific Society Building, 3rd Floor)
Time 6:30 pm – 8:30 pm (Amman-Jordan local time)
For More Info Mohamed Saleh @0788716457
Ayman Farouk    @0795727344
Reminders
image006Live Calendar
image002Facebook event
image004Outlook Calendar
image008Google Calendar