473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reflection problem converting to ASP.NET 2.0

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?

Nov 8 '06 #1
2 1412
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" <Th*********@gmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
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?

Nov 9 '06 #2
Yes, I'm using VS 2005. I'm still having problems. Any suggestions?

Jason

chanmm wrote:
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" <Th*********@gmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
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?
Nov 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
12
by: Antony | last post by:
Hello - I am wanting to print out a "Yes" next to classes that implement "Interface01", otherwise a "No". Here is my code. It crashes with a null reference exception and I am not sure why. Ideas?...
4
by: Bob | last post by:
If you rename a type at design time, the the task list shows what code broke, which happens to be a very nice list of dependant classes and methods. Is there any way to produce such dependency...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
7
by: Nemisis | last post by:
Hi everyone, Can anyone tell me if it is possible to pass in a property of an object into a sub, and within that sub, find out the name of the item that was passed along with the property name??...
5
by: | last post by:
I am having problems with casting or converting a class to to an interface from which it derives. I'm certain that it's due to how it's being loaded, but I'm not sure how to get past the problem....
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.