Re: Creating a Com Component in VB.net 2005



Hi Josh !


" a Reference to 'VbCalendar' could not be added. The Active X type
library 'c:\VbCal\VbCalendar\VbCalendar\bin\Debug\VbCalendar.tlb was
exported from a .net assembly and cannot be added as a reference.

Add a reference to the .net assembly instead. Can someone explain
what this means and how to do it??


It's absolutelly normal, whenever you're trying to import to .Net a
COM component which in fact is .Net assembly and you cannot do
anything about it.
If you want to try your component (and have no VB 6.0), then consider
a use of VBScript as a calling code.

And when it comes to making a COM interoperating .NET assembly:
1. the most recomended way is to define an interface, which is then
implemented by your class and also prevent the class to have
autogenerated interface (which might mess up). This can be achieved by
using an ClassInterface attribute with None value - applied on the
class.
2. if you want to ensure both kinds of bindings, then the interfaced
exposed as COM interface must have InterfaceType.InterfaceIsDual
applied
3. COM clients often use ProgID as class "identifier" when making a
new object of given class. By default, in .Net assembly it is a
namespace and class name coupled together. You can set it as you want
with ProgID attribute.
4. All COM compliant classes must have parameterless constructor.

Examples of the above you can find in my post on the list (VB code,
but attributes names are the same in C#) "How to create a Net assembly
as replacement for existing COM component ".

One more thing: you must sign your assembly (give a strong name, as it
is called in .Net). Project properties/Signing tab - if I'm not wrong.
.



Relevant Pages

  • Re: CreateObject from CLSID
    ... work via VB, but since it only has a CLSID and not a ProgID, it wasn't as ... a simple interface which works perfectly well with VB. ... > What do you mean "Trying to add a reference ... ...
    (microsoft.public.vb.com)
  • Re: Creating a Com Component in VB.net 2005
    ... exported from a .net assembly  and cannot be added as a reference. ... a use of VBScript as a calling code. ... autogenerated interface. ... with ProgID attribute. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: 7.0 wishlist?
    ... The "auto-implement" is intended mainly for the odd situation where an existing class you can't edit fits some interface and you're willing to take responsibility for it if it turns out not to actually adhere to the contract, and try using it where that interface type is expected. ... If reference declarations started showing up with the odd asterisk, bang, or other punctuation mark on it, but never primitive declarations, people would probably be able to guess what was going on, on the basis of "what other binary flag might be set on references but not primitives and would be really useful besides can be/cannot be null?" ... the compiler cannot prove by static analysis that the RHS isn't null might be a good idea. ... Object foo, bar; ...
    (comp.lang.java.programmer)
  • Re: Anders Hejlsberg comment on immutable objects
    ... >explicit interface implementation exists is so an interface name can class ... Improper implicit conversions constitute a nasty ... >> With value types, the variable's value is the object, not a reference ... Consider the affects of our different views on a const ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: please try this program (generic resolution)
    ... of the specific interfaces of a generic interface that has that name and ... either is in the scoping unit in which the reference appears or is made ... And now in my example I misspelled ENISOC. ... external fun ...
    (comp.lang.fortran)

Loading