Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Unable to cast object exceptionUnable to cast object exception
Previous
 
Next
New Post
4/23/2008 7:00 AM
 

Hello everybody,

i have one very annoying exception when I try to use module, developed separatelly from DotNetNuke project and then packed and installed in DotNetNuke from PA. The exception looks like that: Unable to cast object of type 'DotNetNuke.Modules.xx.SqlDataProvider' to type 'DotNetNuke.Modules.xx.DataProvider' (DotNetNuke.Modules.xx is the namespace).
The exception occures here:
objProvider = ((DataProvider)(Framework.Reflection.CreateObject("data", "DotNetNuke.Modules.xx", "")));

in DotNetNuke.Modules.xx.DataProvider class in static CreateProvider() method.

The DotNetNuke.Modules.xx.SqlDataProvider really extends from DotNetNuke.Modules.xx.DataProvider so I'm confused here. It's certainly is ASP issue, but still, maybe someone have met such thing before, so I would appreciate any help..

Kvietinis

 
New Post
4/23/2008 12:16 PM
 

Hi Kvietinis,

I've run across this particular problem a number of times, and it can be very frustrating to solve.  When using the Reflection.CreateObject with a providerType = "Data", DNN will construct the fully qualified object in a very specific manner.  In my experience, it is here that the problem occurs.  Look at the CreateObject overload in Reflection.vb at about line 162 for some details on how this fully qualified object name is constructed.

If I were you, I would add some debugging code before the CreateObject call to ensure that things are happening as you expect.  Something like:

object test = Framework.Reflection.CreateObject("data", "DotNetNuke.Modules.xx", ""));

HttpContext.Current.Response.Write test.GetType().Name;

HttpContext.Current.Response.Write test.GetType().BaseType.Name;

HttpContext.Current.Response.End

 

I'd use this code to ensure (a) that an object is actually created, and (b) that it actually derives from DataProvider.

Hope this gets you started.

Brandon


Brandon Haynes
BrandonHaynes.org
 
New Post
4/24/2008 12:18 AM
 

Hello, Brandon,

i've allready looked what the type of an object, that CreateObject contructs, but I didn't looked what the BaseType of an object. Thanks, for the starting point.

Ignas

 
New Post
4/24/2008 7:22 AM
 

The basetype of an object looks also in way that it has to (Type: DotNetNuke.Modules.xx.SqlDataProvider and the BaseType: DotNetNuke.Modules.xx.DataProvider) so I'm trying to cast DotNetNuke.Modules.xx.SqlDataProvider to DotNetNuke.Modules.xx.DataProvider. I've no idea what the problem is...

 
New Post
4/24/2008 9:28 AM
 

Hi Ignas,

I'm afraid that I don't have too many additional ideas to offer.  Clearly there is some sort of strange typing problem going on. 

Have you tried searching the VS object browser for "DataProvider" and checking to make sure that there isn't a ghost object out there that isn't involved in your inheritance chain?  I've accidently misnamed a partial class before that caused problems like this.

I'd also change your (DataProvider) cast to be more explicit (DotNetNuke.Modules.xx.DataProvider), and I'd probably also play around with the debugging code a bit more to see if I could figure out why VS thinks that SqlDataProvider does not inherit from DataProvider.  Perhaps, in the same code file, create a temporary class that inherits from DataProvider.  Instantiate that class and check that its BaseType is equal to SqlDataProvider's BaseType.

Finally, is there an inner exception or any additional debugging information about the cast error?

Brandon


Brandon Haynes
BrandonHaynes.org
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Unable to cast object exceptionUnable to cast object exception


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out