COM Objects, Early Binding, and Server-Side ASPX Compilation

Discussion in 'ASP .Net' started by =?Utf-8?B?UGxhdA==?=, Jan 21, 2005.

  1. Summary: I've got some *.ASPX pages that still use COM objects. I'd like to
    enable Option Strict, but I get "error BC30574: Option Strict On disallows
    late binding" errors. How can I bypass this problem WITHOUT moving my code
    out of the *.ASPX page or pre-compiling it, and WITHOUT rewriting the COM
    objects as managed .NET code?


    Disclaimer: I understand there is a performance penalty when accessing COM
    objects from managed code, and long to convert these objects to managed code
    one day. However, that is not an option right now. Also, I understand there
    are benefits to pre-compiled code-behind files, however again I'm hoping for
    a solution without involving new code-behinds.


    Example:

    Let's say I'm writing a VB.NET application using Visual Studio, and I want
    to instantiate the COM class "FruitBasket.CAppleBasket". I don't need to use
    a CreateObject call to do this!

    First, I'd add that COM object to my project's "References" folder, as a COM
    reference.

    Second, presumably, I could write code like:
    Dim oBasket as New FruitBasket.CAppleBasket

    Okay, great, so that's the VB.NET/Visual Studio world as I understand it,
    which seems to thwart complaints of late binding (please correct me if I'm
    wrong).


    Now, let's look at a snippet of my (pretend) ASPX page!

    <%
    Dim oBasket as Object = Server.CreateObject("FruitBasket.CAppleBasket")
    oBasket.setColor("red")
    %>

    If my @Page directive sets Strict="True", then I see compilation errors like
    "error BC30574: Option Strict On disallows late binding".

    So I'm left wondering, what (if anything) can I do to prevent late binding
    to these COM objects without significant code changes? Is there a Web.config
    entry, or @Import directive I can use for this?

    Thanks!
     
    =?Utf-8?B?UGxhdA==?=, Jan 21, 2005
    #1
    1. Advertising

  2. In article <>,
    says...
    > Now, let's look at a snippet of my (pretend) ASPX page!
    >
    > <%
    > Dim oBasket as Object = Server.CreateObject("FruitBasket.CAppleBasket")
    > oBasket.setColor("red")
    > %>
    >
    > If my @Page directive sets Strict="True", then I see compilation errors like
    > "error BC30574: Option Strict On disallows late binding".


    You've defined oBasket as type "Object". If you define it as type
    "CAppleBasket", you shouldn't have the error.

    --
    Patrick Steele
    Microsoft .NET MVP
    http://weblogs.asp.net/psteele
     
    Patrick Steele [MVP], Jan 23, 2005
    #2
    1. Advertising

  3. Thanks for taking a stab at it!

    I understand how declaring my variable as the actual type would avoid
    late-binding errors, but instead I see a different error:

    error BC30002: Type 'CAppleBasket' is not defined.

    (And similar errors for attempts at "New FruitBasket.CAppleBasket", "New
    Interop.FruitBasket.CAppleBasket", etc).

    Keeping in mind that CAppleBasket is a COM object, what can I do to make its
    type known to my ASP.NET application?

    Thanks again!

    "Patrick Steele [MVP]" wrote:

    > In article <>,
    > says...
    > > Now, let's look at a snippet of my (pretend) ASPX page!
    > >
    > > <%
    > > Dim oBasket as Object = Server.CreateObject("FruitBasket.CAppleBasket")
    > > oBasket.setColor("red")
    > > %>
    > >
    > > If my @Page directive sets Strict="True", then I see compilation errors like
    > > "error BC30574: Option Strict On disallows late binding".

    >
    > You've defined oBasket as type "Object". If you define it as type
    > "CAppleBasket", you shouldn't have the error.
    >
    > --
    > Patrick Steele
    > Microsoft .NET MVP
    > http://weblogs.asp.net/psteele
    >
     
    =?Utf-8?B?UGxhdA==?=, Jan 24, 2005
    #3
  4. =?Utf-8?B?UGxhdA==?=

    bruce barker Guest

    ..net can not directly access a com object. you either use the pinvoke
    routines, or create a wrapper around the com object. VS will create the
    wrapper if you add a reference of the com object to the project, else use
    the commandline utility tlbimp.exe.

    -- bruce (sqlwork.com)


    "Plat" <> wrote in message
    news:...
    | Thanks for taking a stab at it!
    |
    | I understand how declaring my variable as the actual type would avoid
    | late-binding errors, but instead I see a different error:
    |
    | error BC30002: Type 'CAppleBasket' is not defined.
    |
    | (And similar errors for attempts at "New FruitBasket.CAppleBasket", "New
    | Interop.FruitBasket.CAppleBasket", etc).
    |
    | Keeping in mind that CAppleBasket is a COM object, what can I do to make
    its
    | type known to my ASP.NET application?
    |
    | Thanks again!
    |
    | "Patrick Steele [MVP]" wrote:
    |
    | > In article <>,
    | > says...
    | > > Now, let's look at a snippet of my (pretend) ASPX page!
    | > >
    | > > <%
    | > > Dim oBasket as Object =
    Server.CreateObject("FruitBasket.CAppleBasket")
    | > > oBasket.setColor("red")
    | > > %>
    | > >
    | > > If my @Page directive sets Strict="True", then I see compilation
    errors like
    | > > "error BC30574: Option Strict On disallows late binding".
    | >
    | > You've defined oBasket as type "Object". If you define it as type
    | > "CAppleBasket", you shouldn't have the error.
    | >
    | > --
    | > Patrick Steele
    | > Microsoft .NET MVP
    | > http://weblogs.asp.net/psteele
    | >
     
    bruce barker, Jan 24, 2005
    #4
  5. In article <>,
    says...
    > I understand how declaring my variable as the actual type would avoid
    > late-binding errors, but instead I see a different error:
    >
    > error BC30002: Type 'CAppleBasket' is not defined.
    >
    > (And similar errors for attempts at "New FruitBasket.CAppleBasket", "New
    > Interop.FruitBasket.CAppleBasket", etc).
    >
    > Keeping in mind that CAppleBasket is a COM object, what can I do to make its
    > type known to my ASP.NET application?


    If your COM object was developed in VB6, the "CAppleBasket" actually
    represents the default interface to the COM object. The actual
    createable class would be CAppleBasketClass. Try:

    dim basket as FruitBasket.CAppletBasket = New
    FruitBasket.CAppletBasketClass()

    --
    Patrick Steele
    Microsoft .NET MVP
    http://weblogs.asp.net/psteele
     
    Patrick Steele [MVP], Jan 25, 2005
    #5
  6. Thanks! Sorry for the delay, but this worked, and was exactly what I was
    looking for.

    The only other thing I needed to do was give the impersonated user (e.g.
    aspnetuser) read/execute access to that DLL on the filesystem.

    "bruce barker" wrote:

    > ..net can not directly access a com object. you either use the pinvoke
    > routines, or create a wrapper around the com object. VS will create the
    > wrapper if you add a reference of the com object to the project, else use
    > the commandline utility tlbimp.exe.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Plat" <> wrote in message
    > news:...
    > | Thanks for taking a stab at it!
    > |
    > | I understand how declaring my variable as the actual type would avoid
    > | late-binding errors, but instead I see a different error:
    > |
    > | error BC30002: Type 'CAppleBasket' is not defined.
    > |
    > | (And similar errors for attempts at "New FruitBasket.CAppleBasket", "New
    > | Interop.FruitBasket.CAppleBasket", etc).
    > |
    > | Keeping in mind that CAppleBasket is a COM object, what can I do to make
    > its
    > | type known to my ASP.NET application?
    > |
    > | Thanks again!
    > |
    > | "Patrick Steele [MVP]" wrote:
    > |
    > | > In article <>,
    > | > says...
    > | > > Now, let's look at a snippet of my (pretend) ASPX page!
    > | > >
    > | > > <%
    > | > > Dim oBasket as Object =
    > Server.CreateObject("FruitBasket.CAppleBasket")
    > | > > oBasket.setColor("red")
    > | > > %>
    > | > >
    > | > > If my @Page directive sets Strict="True", then I see compilation
    > errors like
    > | > > "error BC30574: Option Strict On disallows late binding".
    > | >
    > | > You've defined oBasket as type "Object". If you define it as type
    > | > "CAppleBasket", you shouldn't have the error.
    > | >
    > | > --
    > | > Patrick Steele
    > | > Microsoft .NET MVP
    > | > http://weblogs.asp.net/psteele
    > | >
    >
    >
    >
     
    =?Utf-8?B?UGxhdA==?=, Mar 16, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn
    Replies:
    0
    Views:
    454
    Shawn
    Dec 8, 2003
  2. =?Utf-8?B?QXJuZQ==?=

    Server side code in-side aspx

    =?Utf-8?B?QXJuZQ==?=, Apr 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    588
    Brock Allen
    Apr 18, 2005
  3. Mr Flibble
    Replies:
    8
    Views:
    38,451
    Will Asrari
    May 23, 2006
  4. Olaf Meding

    MS COM early and late binding

    Olaf Meding, Apr 27, 2004, in forum: Python
    Replies:
    4
    Views:
    408
    Simon Brunning
    Apr 28, 2004
  5. Replies:
    2
    Views:
    867
    Kevin Grover
    Oct 20, 2006
Loading...

Share This Page