Reflection problem converting to ASP.NET 2.0

T

TheLongshot

Ok, let's try this again.

I have an ASP.NET 1.1 application that I'm working to convert to 2.0,
but I've run into a snag.

The problem is with this line:

return
(IDataProviderBase)(((ConstructorInfo)cache["IDataProviderBase"]).Invoke(null)
);

This is supposed to create an object that uses the IDataProviderBase
interface. The cache contents are created here:

cache.Insert( "IDataProviderBase", Assembly.LoadFrom(
assemblyPath).GetType( className ).GetConstructor(new Type[0]), new
CacheDependency( assemblyPath ) );

className is a string from Web.Config with the fully qualified class
name ("AppName.Components.DataAccess.SQLDataAccess", for example).

So, the constructor is stored in the cache, and is invoked when the
first bit of code is executed. Problem is, I'm getting an
InvalidCastException there, and I have no idea why. I've tried casting
to the object being created with the same result. (Unable to cast
object of type 'AppName.Components.DataAccess.SqlDataProvider' to type
'AppName.Components.DataAccess.SqlDataProvider') I was able to assign
it to an Object object, and doing a GetType returns what I expected,
but I still can't cast it to the appropriate object.

So, any idea why this is happening?
 
C

chanmm

ASP.NET 1.1 to 2.0 I do hit a lot of tiny problems too. Are you converting
your 1.1 to 2.0 using VS 2005? If not then please do so. If you are doing
manual converting then ...

chanmm
 
T

TheLongshot

Yes, I'm using VS 2005. I'm still having problems. Any suggestions?

Jason
ASP.NET 1.1 to 2.0 I do hit a lot of tiny problems too. Are you converting
your 1.1 to 2.0 using VS 2005? If not then please do so. If you are doing
manual converting then ...

chanmm

TheLongshot said:
Ok, let's try this again.

I have an ASP.NET 1.1 application that I'm working to convert to 2.0,
but I've run into a snag.

The problem is with this line:

return
(IDataProviderBase)(((ConstructorInfo)cache["IDataProviderBase"]).Invoke(null)
);

This is supposed to create an object that uses the IDataProviderBase
interface. The cache contents are created here:

cache.Insert( "IDataProviderBase", Assembly.LoadFrom(
assemblyPath).GetType( className ).GetConstructor(new Type[0]), new
CacheDependency( assemblyPath ) );

className is a string from Web.Config with the fully qualified class
name ("AppName.Components.DataAccess.SQLDataAccess", for example).

So, the constructor is stored in the cache, and is invoked when the
first bit of code is executed. Problem is, I'm getting an
InvalidCastException there, and I have no idea why. I've tried casting
to the object being created with the same result. (Unable to cast
object of type 'AppName.Components.DataAccess.SqlDataProvider' to type
'AppName.Components.DataAccess.SqlDataProvider') I was able to assign
it to an Object object, and doing a GetType returns what I expected,
but I still can't cast it to the appropriate object.

So, any idea why this is happening?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top