Friday, May 4, 2007

ObjectDataSource ?

I want to give you a hint of something that bothered me the last hours:
The type specified in the TypeName property of ObjectDataSource '' could not be found.
This is the Error I was getting the last half an hour and that drove me crazy.
A simple definition lays behind in the code:

ObjectDataSource odsP = new ObjectDataSource();
odsP.TypeName = "OrderDoc";
odsP.SelectMethod = "GetPriceDetails";

Why then the message is with EMPTY TypeName ?
Well, if you have the definition of the OrderDoc in the scope (namespace) of your current project that is executing the code - there is no problem at all.
The problem comes out when you place your business logic in a business logic layer. And there is no matter how you add the reference to the BL project. You would never succeed.
The answer lays behind the mechanisim the ObjectDataSource is searching for the given TypeName. Well, it uses Reflection, so you must provide a fully-qualified name of the Type including the assembly / namespace. For example:
So the lines in the example will turn onto:

ObjectDataSource odsP = new ObjectDataSource();
odsP.TypeName = "MyBusinessLogic.OrdersLogic.OrderDoc";
odsP.SelectMethod = "GetPriceDetails";



T600 said...

Thanks Anton, that was a big help with a similar problem that had held me back for hours!


Anonymous said...

Thanks for pointing that out.
I had that for a previous object and Still forgot to fully qualify another new one!