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?
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?