473,780 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;
COMAdminCatalog Collection objApplications Coll = null;
COMAdminCatalog Object objApp = null;
try
{
objType =
Type.GetTypeFro mProgID("COMAdm in.COMAdminCata log");
objCatalog =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(objType));

It is part of setup application...s o 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 =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(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 2208
Hi,

The most probable reason is that System.Activato r.CreateInstanc e(objType) is
returning null

or alternatively the instance returned cannot be casted to COMAdminCatalog

do this:

object o = System.Activato r.CreateInstanc e(objType);
//LOG if o is null or not
//log o.GetType().ToS tring(); //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.goo glegroups.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;
COMAdminCatalog Collection objApplications Coll = null;
COMAdminCatalog Object objApp = null;
try
{
objType =
Type.GetTypeFro mProgID("COMAdm in.COMAdminCata log");
objCatalog =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(objType));

It is part of setup application...s o 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 =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(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 ICOMAdminCatalo g 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 StyleGalleryCla ss)

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.__ComObj ect 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.co m

<al******@gmail .comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.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;
COMAdminCatalog Collection objApplications Coll = null;
COMAdminCatalog Object objApp = null;
try
{
objType =
Type.GetTypeFro mProgID("COMAdm in.COMAdminCata log");
objCatalog =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(objType));

It is part of setup application...s o 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 =
(COMAdminCatalo g)(System.Activ ator.CreateInst ance(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
3640
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: "Specified cast is not valid." The only thing i put there was a "test this." inside the form. What might be the problem here? Thanks in advance. The Exception:
4
7043
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
10519
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 columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the value in the db. Here is the code that is causing it as well as the error (below). ERROR...
2
3092
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: try {
3
2185
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
623
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 not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> System.InvalidCastException: Specified...
0
1627
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. ----------------------------------------------------------- Server VS.NET 2003 SQLServer 2000 IIS 66.0
3
12436
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: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
2
8785
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; Microsoft.Web.UI.WebControls.TreeNode iNode = null;
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.