Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 6 of 6

C#: InvalidCastException ApplicationClass app = new ApplicationClass()

This is a discussion on C#: InvalidCastException ApplicationClass app = new ApplicationClass() within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi there, I've got the following problem: I am trying to build a simple application with VS 2005 and MapPoint ...

  1. #1
    Chrissivo is offline Junior Member White Belt
    Join Date
    Jan 2007
    Posts
    3

    Question C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    Hi there,
    I've got the following problem:
    I am trying to build a simple application with VS 2005 and MapPoint 2004. I have read an article (http://www.mp2kmag.com/a103--chandu.thota.net.framework.mappoint.html) and tried the given example. It didn't work...
    So I tried to build the code line by line:
    Code:
     
     
    using MapPoint;
    /* ... */
    public void makeMap()
    {
    ApplicationClass app = null;
    app = new ApplicationClass();
    app.Visible = true;
    /* ... */
    }
    At line four I get an InvalidCastException (InvalidCastException: Unable to cast COM object of type "MapPoint.ApplicationClass" to interface type "MapPoint._Application") (the message may vary, though I translated it from German). Even before this line is executed, the debugger gives me the information, that the object app has InvalidCastExceptions on all variables...
    I must add, that the code I tried here, was originally developed for VS .NET. Could that be the problem?
    Maybe someone can help me, I'm looking forward to.
    Thanks
    Christian

    PS: The original error message is: InvalidCastException was unhandled
    Das COM-Objekt des Typs "MapPoint.ApplicationClass" kann nicht in den Schnittstellentyp "MapPoint._Application" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{D6D389CE-1781-47A0-8984-4349687F65D6}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).

    PPS: Why is the forum search engine finding zero mathches for "C#"?

  2. #2
    Paul Larson is offline Senior Member Green Belt
    Join Date
    Sep 2005
    Location
    Battle Creek, Michigan
    Posts
    136

    Re: C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    You're simply using the wrong interfaces for your intent.
    I assume you've added a reference to the MPNA82.TLB file in your project.

    Note: It is good practice to fully-qualify your references to avoid typecast errors.



    public partial class Form1 : Form
    {
    private MapPoint.Application oMPApp;
    private MapPoint.Map oMap;
    ......

    private void makeMap()
    {
    oMPApp=new MapPoint.Application();
    oMPApp.UserControl = true;
    oMPApp.Visible = true;
    oMap = oMPApp.ActiveMap;
    }
    .......


    HTH
    Paul

  3. #3
    Chrissivo is offline Junior Member White Belt
    Join Date
    Jan 2007
    Posts
    3

    Unhappy Re: C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    Hi Paul,
    thanks for your reply, but this does not seem to be the solution for my problem.
    Well I didn't add the MPEU82.TLB till now, but have had a reference to the COM-interface.

    I tried your code snippet, but I still get this error message
    Well thnk you anyway for your help

    Christian

  4. #4
    Paul Larson is offline Senior Member Green Belt
    Join Date
    Sep 2005
    Location
    Battle Creek, Michigan
    Posts
    136

    Re: C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    If you like, zip up your project and email it to me:
    plarsonpma(at)hotmail(dot)com

    I'll review it and send it back corrected.
    If nothing's wrong with your project, then it would point to a bad installation or registry of MapPoint itself.

    -Paul

  5. #5
    Chrissivo is offline Junior Member White Belt
    Join Date
    Jan 2007
    Posts
    3

    Re: C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    Hi there,
    the problem was, that MapPoint 2004 hasn't been installed properly. A simple repair of the installation ended my problem.
    This might have occured, because I have had installed a MapPoint 2006 Trial temporarily.
    Many Thanks to Paul

    Christian

  6. #6
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: C#: InvalidCastException ApplicationClass app = new ApplicationClass()

    Hi,

    thanks for feedback.
    If you have more versions of mappoint you have to be sure to register the one for whitch you want to compile. you can do that from command interpreter: mappoint.exe /registerserver

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. InvalidCastException in OpenMap
    By kdulaney in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 02-03-2005, 06:20 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96