Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:01:28+00:00 2026-05-27T11:01:28+00:00

Background I am working on a trading ActiveX API in visual studio 2010 on

  • 0

Background

I am working on a trading ActiveX API in visual studio 2010 on C#. Since it is an ActiveX API, I simply added the ActiveX as my reference. The api provides three group of things: Method you could use to call API, the Event with which the API updates information for you and some socalled ActiveX COM object.

ISSUE

I asked a related question here: C# boolean int conversion issue Finally, after viewing the exception has been thrown, I know that it is about casting. Here is the description of exception:

*System.InvalidCastException was unhandled Message=Unable to cast object of type  
InteractiveBrokersTradingSystem.Forex' to type 'TWSLib.IContract'.

*

And here is my definition for Forex Class:

namespace InteractiveBrokersTradingSystem
{
  class Forex:TWSLib.IContract
  {


    public int conId { get; set; }
    public string symbol { get; set; }
    public string secType { get; set; }
    public string expiry { get; set; }
    public double strike { get; set; }
    public string right { get; set; }
    public string multiplier { get; set; }
    public string exchange { get; set; }
    public string primaryExchange { get; set; }
    public string currency { get; set; }
    public string localSymbol { get; set; }
    public int includeExpired { get; set; }
    public object comboLegs { get; set; }
    public object underComp { get; set; }
    public string comboLegsDescrip { get;set; }
    public string secIdType { get; set; }
    public string secId { get; set; }

    public Forex(string preCurrency,string baseCurrency)
    {
        //conId = 0;
        //symbol = preCurrency;
        //secType = "CASH";
        //expiry = null;
        //strike = double.Parse("0");
        //right = null;
        //multiplier = null;
        //exchange = "IDEALPRO";
        //primaryExchange = "IDEALPRO";
        //currency = baseCurrency;
        //localSymbol = null;
        //includeExpired = 0;
       // comboLegs = null;
        //underComp = null;
        //comboLegsDescrip = null;
        //secType = null;
        //secId = null;


      }
   }
 }

You could see that I did not assign any value to the properties of the class and the exception is always the same no matter what kind of value I assign or not assign or null.

In the description of the api below as image we can see that some property with () like strike() as doulble and some not with () like secType as string; someone told me that it might be problem. Please, give me any hint related to this COM casting issue:

a busy cat
(source: minus.com)

a busy cat
(source: minus.com)

a busy cat
(source: minus.com)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:01:29+00:00Added an answer on May 27, 2026 at 11:01 am

    Can you post some code that actually fails?

    I think what’s happening is that you’re trying to cast a COM object to a plain .NET type and that will not work because the COM object needs to explicitly be mapped to a .NET type either by the Runtime Callable Wrapper or by manual mapping.

    One suggestion I would have is to skip explicit casting and use the dynamic type in .NET 4.0 to access the properties of your COM object, then map it to whatever properties/objects you need it to. That way you’ll be able to see exactly which part of the object doesn’t want to map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long-Winded Background I'm working on parallelising some code for cardiac electrophysiology simulations. Since users
Background: We have an offshore group working up a Silverlight 2 prototype for us.
Background: working a user q&a site where users logged,etc. What user/visitor data should be
Background I am working on a legacy small-business automation system (inventory, sales, procurement, etc.)
Background I am working on a phonetic converter program which converts english text into
Background: Trevor was working on a test project solely for the purpose of trying
First some background: I'm working on an application and I'm trying to follow MVVM
First, the background: I'm working in Tapestry 4, so the HTML for any given
Ok, I need help. This is my first question here. Background: I am working
Background - I can get HttpListener working fine for HTTP traffic. I'm having trouble

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.