473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
5 1856
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
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
..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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: J Overholt | last post by:
I have a COM object I am using and I am having some problems setting a property, I get an "PropPut() failed: Member not found". The property I am setting is another COM object. Here's is the...
1
by: aaapaul | last post by:
Hello ! Can anybody tell me, whats the difference between these two classes ? Public Class clsOutlook Private objAppOutlook As Object Sub New()
5
by: Colin Anderson | last post by:
I discovered, with great excitement, this article http://www.davison.uk.net/vb2notes.asp when researching methods for emailing from Access via Notes. Unfortunatly, when I run this I get a...
2
by: Mystery Man | last post by:
We are developing a C# application that has many interfaces to the Microsoft suite (eg Word, Excel, Outlook, Powerpoint, etc). We need to support Office 97, 2000, 2002 and any future versions. ...
6
by: Martin Eyles | last post by:
I have just turned on option strict in ASP/VB.net. I started by happily going through and setting up all of the Dim statements with As clauses, and making my cast explicit. However, I have now got...
4
by: al | last post by:
Greetings, I'm confused about obejects handling in vb.net. For example, why when including NEW in some declaration cuases error, like Dim FormBinding As New Binding 'This causes an error...
1
by: Roland | last post by:
Hello, I'm trying to use Sparx Systems Enterprise Architect OLE automation interface. There is no problem to get early binding interface using Microsoft Visual Basic. But using win32com makepy...
2
by: kogrover | last post by:
ISSUE: COM Excel Sort works with Early Binding, but not Late Binding, but py2exe only does Late Binding I have code similar to this (type from notes, so there may be a typo...) import...
3
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
1
by: pedestrian via DotNetMonster.com | last post by:
What are the example of early binding? How about late binding? Thank you for replying. (: -- Warmest Regards, Pedestrian Message posted via DotNetMonster.com
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.