November 2004 - Posts - Ed's Blog
in

dotnet.org.za

South African .NET Developer Portal

Ed's Blog

Object reference not set to an instance of an object

November 2004 - Posts

  • Data-Binding to Web Service Proxies

    I had to do this today(bind an array of objects returned by a web service) and it turns out that the a datagrid can't bind to public fields on objects. It only binds to public properties. That's fine with me, except that the wsdl.exe utility that generates web service proxies, converts all the properties of the object that is returned by the web service, to public fields in proxy object. There is no aparent way to tell it to do something different.

    Then I found this post by Brian Ritchie. He basically took the wsdl tool from the Mono project [.NET on Linux] and added some code to map wsdl attributes to properties instead of public fields.

    So now I'm in bindable heaven again. Thanks Brian!

    PS: The properties on the object that gets returned by the web services must have get; and set; operations, otherwise it won't be mapped in the proxy object at all.

  • Sun Microsystems - The big bad corporate monster

    One always get the idea that the Sun/Java community tries to create the image that Microsft is the big bad corporate that wants to take over the world and dictate to everyone what they can and can't do and in what way etc. etc. On the other side they try to portray themselves as the big loving family where everything is open, everyone has a say, everyone's opinion is important etc.

    So it was interesting to read this post by Ted Neward who's being taken on by Sun for having a website called “Javageeks.com”. It apears that apart from the name, some parts of the website will “confuse consumers” as to whether the site is linked to or sponsored by Sun. MY GOSH, there are millions of websites all over the world that use “java“ in their name and their content. Is Sun gonna police the internet now and take down the very people that are promoting their products ? Are the also going to take on every book ever published that has “java“ in the title or in the text ?

    At the end of the day, Sun, like Microsoft, is a company that is trying to make money. They shoot down MS for the very things they do themselves? As far as I'm concerned the only difference between them is the business model, but the goal is the same, the rest is just propaganda and sales talk. 

    Posted Nov 30 2004, 08:29 AM by eduard with no comments
    Filed under:
  • w.bloggar

    This is my first post from my desktop, if you see this it means that w.bloggar is working from my pc. It also means that IMHO is not. I tried IMHO but got some weird errors, it wouldn't publish. So w.bloggar it is.
    Posted Nov 26 2004, 07:57 AM by eduard with 2 comment(s)
    Filed under:
  • Default Button control - very nice

    The .Text guy, Scott Watermasysk, create a textbox control where you can set the button that must be click if the person hits enter while the textbox has focus. I recon it's very nice. We had quite a big issue putting the same behaviour in an existing system, this would have helped a lot.

    Get it here

  • Stored procedures are bad, m'kay?

    Frans Bouma sets out his arguments for why inline sql is just as good, and better than using storeprocs for data access. I must say that I agree with him. I'm currently busy creating 2 application frameworks for an upcoming project, one uses nHibernate (which generates sql on the fly) and one that uses storeprocs. The amount of extra code, work and maintenance that goes into the storeproc framework is staggering !

    I also understand that Axapta also does not use storeprocs for data access, can it be that Microsoft agrees with inline sql ?

  • I'm Agent Smith !!

    Posted Nov 23 2004, 01:50 PM by eduard with no comments
    Filed under:
  • Comparison of IoC implementations

    I found this article that compares HiveMind, PicoContainer and Spring as Inversion of Control frameworks. If you don't know what IoC is, you can check out the definitive article by Martin Fowler here.

    Although these frameworks are for java, it is pleasing to note that both Spring and PicoContainer has .NET ports.

    Posted Nov 23 2004, 08:41 AM by eduard with no comments
    Filed under:
  • FINALLY

    We get the first wicket, my gosh ! we sure took oor sweet time :

      52.3 Pollock to Gambhir, OUT: full and angling away from the left-
            hander, Gambhir goes for a tentative drive this time and the ball
            kisses the edge and goes to Thami Tsolekile who takes a good catch
            falling to his left! That is the fall of the first Indian wicket!

    India are 218/1, it's gonna be a long day!

    Posted Nov 23 2004, 07:31 AM by eduard with no comments
    Filed under: ,
  • Bookmarks in visual studio

    I discovered some cool shortcut keys in Visual Studio for bookmarks. I haven't seen to many developers using these so I thought I'd mention it. Ctrl + K + K marks a line with a bookmark. This is very useful to in extremely long files where you want to work on an area, scroll away and then return now you can insert the bookmark the scroll away and press Ctrl + K + N to return. The 'N' is for next. There is also a 'P' for previous as you can of course have multiple bookmarks in the same file. Check out View | Bookmarks menu for all the options.

    The most interesting thing for me was that the shortcut keys matches the ones in the Turbo Pascal 6 IDE - big blast from the past !

     

    Posted Nov 19 2004, 07:29 AM by eduard with 5 comment(s)
    Filed under:
  • Kerio Personal Firewall

    It came as a bit of a blow that Tiny sofware no longer has a free version of their firewall. But then I discovered Kerio Personal Firewall while looking for a replacement. It seems to have taken over the Tiny engine or something because the 2 firewalls look basically the same and work the same. Kerio is a bit better though and a bit more flexable.

    I can really recommend it. Nice balance between of user friendly and power.


    Get it here [of course it's free]

    Posted Nov 18 2004, 01:03 PM by eduard with 1 comment(s)
    Filed under:
  • MS releases Enterprise Development Reference Architecture V1.1

    The new version is now avalible on their gotdotnet workspace.

    I must say that this area of work, previous known as ShadowFax, does not seem to get a lot of attention. I wonder what Microsoft's position is on this ? How official is this project as a reference Architecture for Microsoft enterprise projects ?

  • 15 Commandments to Curb Bad Programmer Habits

    you can find them here. I particularly like no 13 :)

    1. Thou shalt not break the unit tests or system functionality (by checking in half done crap code to CVS)
    2. Thou shalt really understand the requirements driving your work (not make them up or not bother to read them and/or not ask questions when necessary)
    3. Thou shalt deliver what the customer needs (not that which is easy to implement)
    4. Thou shalt estimate work effort accurately (and deliver within agreed estimates)
    5. Thou shalt understand the implications of thy work with respect to others on the team
    6. Thou shalt not just comment out code because it causes the test to fail (without understanding why it was there in the first place)
    7. Thou shalt understand the implications of thy work with respect to other areas of the system as a whole
    8. Thou shalt follow the business priorities (not just do what you think is interesting)
    9. Thou shalt deliver stuff that actually works - including the user interface that can't be jUnit tested (i.e. actually try it out rather than hoping for the best - test the UI - don't just leave it for the external tester to find as that is "their job")
    10. Thou shalt not regard communicating with other members of the team as an unnecessary and tiresome overhead that can be ignored
    11. Thou shalt not deviate from the "agreed" development approach without a good reason that has been thought about
    12. Thou shalt understand that the external image of the development team is important - even though it does not contribute to your daily work
    13. Thou shalt not call the customer a wanker even when it is true. <ok, can't have this on the wall>
    14. Thou shalt understand that sometimes thou must do things because they are important to other people's jobs (thou art not the only person in the universe)
    15. Thou shalt understand that getting the software out there, so others can see something has actually been done, is important (we're not just doing this as an intellectual exercise)

    Posted Nov 17 2004, 08:01 AM by eduard with no comments
    Filed under:
  • Object service lookup using the Spring.NET framework

    In a recent post I was wondering how one can do a lookup for the current implementation of an object service. Armand pointed me to the Spring.NET framework (a port of the Java Spring framework). Following here is a quick example of how I used it. (The framework can do a lot more than what I show here - it has a complete dependancy injection/container framework for example)

    First thing is to download and extract the zip file, compile the source and reference the Core and Context namespaces in your project.

    Continuing with my Logger example you can declare an interface for your service :

    namespace Tester
    {
      public interface ILogger
      {
        string logStuff(string stuff);
      }
    }

    Then we update our projects .config file to point to the current implementation:

    <configSections>
      <section name="objects" type="Spring.Context.Support.ApplicationContextHandler,Spring.Context"/>
    </configSections>

    <objects>
      <object name="Tester.ILogger" class="Tester.MyLogger,Tester">
        <constructor-arg index="0">
          <value>c:\Bla.txt</value>
        </constructor-arg>
      </object>
    </objects>

    This basically says that the class MyLogger is the current implementation for ILogger. Note that the name of the object could have been any unique string, but I prefer the class name, it's more useful. Here is the MyLogger class:

    namespace Tester
    {
       public class MyLogger : ILogger
      {
        private string _file;
        public MyLogger(string file) { _file = file; }

        public string logStuff(string stuff)
        {
            //log the stuff to the file here
        }
      }
    }

    The idea is that if we don't want to log to the file anymore, we can just create our new class(for example to log to the application log), make it implement ILogger and then change the config file to the new implementation. [We would also need to remove the constructor-arg tag from the config file].
    It goes without saying that the rest of your code should only use the interface.
    Here is how your code would get a reference to the current implementation.

    IApplicationContext ctx = (IApplicationContext) ConfigurationSettings.GetConfig("objects");
    ILogger log = (ILogger)ctx.GetObject("Tester.ILogger");
    log.logStuff("hello logger");

    As you can see, we've achieved complete seperation between the interface and the current implementation.
    you can also wrap the service lookup generically with a method like this:

    public class ServiceLookup
    {
      protected ServiceLookup() { }
     
      public static object getService(Type serviceType)
     {
        IApplicationContext ctx = (IApplicationContext) ConfigurationSettings.GetConfig("objects");
        return ctx.GetObject(serviceType.ToString());
       }
    }

    Then if you have a bunch of services define, you can access them like this:

    ILogger log = ServiceLookup.getService(typeof(ILogger));

    If you want to share an implemenation object across a process (note: not a thread or web request) you can make it a singleton, which will force Spring to create one instance an the return that same instance every time it is requested. You do this in the config file:

    <object name="Tester.ILogger" class="Tester.MyLogger,Tester" singleton="true" />

  • That other Access Denied error - the one with - add assembly="*"

    I Killed that bastard of an error ! It turns out that Indexing service (what a piece of junk software) is locking some temporary ASP.NET files. Below is an example of the error message. To fix it, basically disable your indexing service(make sure to set it to not restart the service when you restart). Check out the article here if you want to solve it without disabling indexing service.

    Error example:

    Server Error in '/MyWebApp' Application
    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Access is denied: 'mydll'.

    Source Error:

    Line 169: <add assembly=<System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>/>

    Line 170: <add assembly=<System.EnterpriseServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>/>

    Line 171: <add assembly=<*>/>

    Line 172: </assemblies>

    Line 173:

    Update : I came across this problem again and found another solution - check it out here

  • Links to tools

    Stuart asked me to put up a link up to nHibernate, so I decided to create a tool links list on my blog. I've created the list with links to the 2 frameworks I'm currently looking at: nHibernate and Spring. I'll put up some other links in a while.

     

More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems