473,394 Members | 1,866 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.

COM Creation - Specified Cast is Not Valid

Hello,

I have the following method to help me in installing some COM
components onto the machine...below is a snippet that is causing the
problem...

Type objType = null;
COMAdminCatalog objCatalog = null;
COMAdminCatalogCollection objApplicationsColl = null;
COMAdminCatalogObject objApp = null;
try
{
objType =
Type.GetTypeFromProgID("COMAdmin.COMAdminCatalog") ;
objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

It is part of setup application...so when I run the setup on my
machine, it works fine....

However, when I try to test it on one of our servers.....I get a
Specified Cast is Invalid exception from this line objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

I am guessing its a problem with either one of the last two
line....forgive me, im new to COM

Thanks in advance

Sep 1 '06 #1
3 2194
Hi,

The most probable reason is that System.Activator.CreateInstance(objType) is
returning null

or alternatively the instance returned cannot be casted to COMAdminCatalog

do this:

object o = System.Activator.CreateInstance(objType);
//LOG if o is null or not
//log o.GetType().ToString(); //to get the type of the instance created
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<al******@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hello,

I have the following method to help me in installing some COM
components onto the machine...below is a snippet that is causing the
problem...

Type objType = null;
COMAdminCatalog objCatalog = null;
COMAdminCatalogCollection objApplicationsColl = null;
COMAdminCatalogObject objApp = null;
try
{
objType =
Type.GetTypeFromProgID("COMAdmin.COMAdminCatalog") ;
objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

It is part of setup application...so when I run the setup on my
machine, it works fine....

However, when I try to test it on one of our servers.....I get a
Specified Cast is Invalid exception from this line objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

I am guessing its a problem with either one of the last two
line....forgive me, im new to COM

Thanks in advance

Sep 1 '06 #2
I actually managed to come up with a solution (I think :S)...

I changed objCatalog from COMAdminCatalog to ICOMAdminCatalog for the
following reasons:

Sometimes you may find that casting a variable fails when you think it
should succeed (the solution is often to declare variables as interface
Types and avoid the use of class types, for example, use IStyleGallery
rather than StyleGalleryClass)

When you create a new COM object in .NET via interop, you get a
reference to your object that is wrapped in a strongly typed runtime
callable wrapper (RCW). A RCW is a wrapper that can hold a reference to
a COM object inside a .NET application.

Even if you actually know the exact Type of class to which you have a
reference, the .NET runtime still does not have the metadata required
to cast the variable to a strongly typed RCW.

However, as the System.__ComObject class is specifically designed to
work with COM objects, it is always able to perform a QI to any COM
interfaces that are implemented by an object. Therefore, casting to
specific interfaces (as long as they are implemented on the object)
will be successful.

Sep 1 '06 #3
When dealing with COM, you should always work with the interface
definitions, and cast to that. COM is an interface-based framework, and it
only makes sense to work with interfaces.

When you see class types that represent COM objects, they really don't
honor the way that COM works, as it is an amalgam of all the interfaces that
the type implements. This is close to how VB works, and to be quite honest,
I don't recommend it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<al******@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hello,

I have the following method to help me in installing some COM
components onto the machine...below is a snippet that is causing the
problem...

Type objType = null;
COMAdminCatalog objCatalog = null;
COMAdminCatalogCollection objApplicationsColl = null;
COMAdminCatalogObject objApp = null;
try
{
objType =
Type.GetTypeFromProgID("COMAdmin.COMAdminCatalog") ;
objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

It is part of setup application...so when I run the setup on my
machine, it works fine....

However, when I try to test it on one of our servers.....I get a
Specified Cast is Invalid exception from this line objCatalog =
(COMAdminCatalog)(System.Activator.CreateInstance( objType));

I am guessing its a problem with either one of the last two
line....forgive me, im new to COM

Thanks in advance

Sep 4 '06 #4

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

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.