Create COM object / Marshal.GetActiveObject

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    Create COM object / Marshal.GetActiveObject

    I want to get an active Word.Applicatio n, via

    using System.Runtime. InteropServices ;
    using Word;
    ...
    object obj = Marshal.GetActi veObject("Word. Application");
    _Application wordApp = obj as _Application;

    It works fine at my developer computer. At an other computer the application
    crash with an exception.
    But I can't catch the exception.

    Anybody know what is wrong.

    Thanks in advance
    Thomas


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Create COM object / Marshal.GetActi veObject

    Thomas,

    Are you trying to catch an Exception (and not a more specific one)? If
    you do, you should catch it. My guess is that you are getting an
    InvalidCastExce ption. The reason for this would most likely be that your
    other computer is running a different version of excel, and therefore, the
    interface definitions are different than the version you developed against.

    In order to get around this, you would need to make the calls in a late
    bound manner, if you want to support multiple versions.

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m


    "thomas" <t.wegener@mum. de> wrote in message
    news:%23X1TvTT$ EHA.2032@tk2msf tngp13.phx.gbl. ..[color=blue]
    >I want to get an active Word.Applicatio n, via
    >
    > using System.Runtime. InteropServices ;
    > using Word;
    > ...
    > object obj = Marshal.GetActi veObject("Word. Application");
    > _Application wordApp = obj as _Application;
    >
    > It works fine at my developer computer. At an other computer the
    > application crash with an exception.
    > But I can't catch the exception.
    >
    > Anybody know what is wrong.
    >
    > Thanks in advance
    > Thomas
    >[/color]


    Comment

    • Thomas

      #3
      Re: Create COM object / Marshal.GetActi veObject

      Hi Nicholas,

      1. How can I use in c# late binding?
      2. I assume there is security problem.
      If I call 'C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \ConfigWizards. exe'
      and select the executable as trustable, the exe is running.

      Do you know how I can ensure that the assembly is running at every computer
      without to use the configWizard?

      Cheers Thomas

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> schrieb
      im Newsbeitrag news:u7Q7UmY$EH A.2568@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Thomas,
      >
      > Are you trying to catch an Exception (and not a more specific one)? If
      > you do, you should catch it. My guess is that you are getting an
      > InvalidCastExce ption. The reason for this would most likely be that your
      > other computer is running a different version of excel, and therefore, the
      > interface definitions are different than the version you developed
      > against.
      >
      > In order to get around this, you would need to make the calls in a late
      > bound manner, if you want to support multiple versions.
      >
      > Hope this helps.
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      >
      > "thomas" <t.wegener@mum. de> wrote in message
      > news:%23X1TvTT$ EHA.2032@tk2msf tngp13.phx.gbl. ..[color=green]
      >>I want to get an active Word.Applicatio n, via
      >>
      >> using System.Runtime. InteropServices ;
      >> using Word;
      >> ...
      >> object obj = Marshal.GetActi veObject("Word. Application");
      >> _Application wordApp = obj as _Application;
      >>
      >> It works fine at my developer computer. At an other computer the
      >> application crash with an exception.
      >> But I can't catch the exception.
      >>
      >> Anybody know what is wrong.
      >>
      >> Thanks in advance
      >> Thomas
      >>[/color]
      >
      >[/color]


      Comment

      Working...