By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
In article <BF**********************************@microsoft.co m>,
Pl**@discussions.microsoft.com 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
Nov 19 '05 #2

P: n/a
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 <BF**********************************@microsoft.co m>,
Pl**@discussions.microsoft.com 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

Nov 19 '05 #3

P: n/a
..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" <Pl**@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
| 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 <BF**********************************@microsoft.co m>,
| > Pl**@discussions.microsoft.com 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
| >
Nov 19 '05 #4

P: n/a
In article <5A**********************************@microsoft.co m>,
Pl**@discussions.microsoft.com 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
Nov 19 '05 #5

P: n/a
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" <Pl**@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
| 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 <BF**********************************@microsoft.co m>,
| > Pl**@discussions.microsoft.com 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
| >

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.