Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot create a file when that file already exits

Status
Not open for further replies.

aTekTipsUser

Programmer
Nov 8, 2004
68
US
I am trying to create a com library in vb.net. I have copied the example in Visual Studio Walkthrough:

Walkthrough: Creating COM Objects with Visual Basic .NET
Step 1 - 2 Create new project
Step 3. Select add new Item...
Step 4. Select COM class from the Templates list...
Step 5. Add code...
Step 6. Select Build Solution from the Build menu. Visual Basic .NET builds the assembly and registers the COM object with the operating system.

Here is the code:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "3E7D58F9-7BC7-41E6-8D59-8CE319CDB094"
Public Const InterfaceId As String = "B9BE411A-83CE-4023-B330-766828937787"
Public Const EventsId As String = "BD9FF711-EB89-41E8-8401-BF0F1CF8284A"
#End Region

Private _test As String

' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub

Public Property GetTest() As String
Get
Return _test
End Get
Set(ByVal Value As String)
_test = Value
End Set
End Property
End Class

When I run from Access I get the error:
Run-time error -2147024713' Automation error Cannot create a file when the file already exists.

Here is the code in Access:
Dim c As ComClassTest.ComClass1
Set c = New ComClassTest.ComClass1
MsgBox c.GetTest

The error occurs at Set C = New...

Thanks in advance for your help!
 
I haven't created a COM class in .Net, but what we have done is create a .Net library and a COM wrapper for it.

This can be done by setting the "Register for COM interop" flag on the project properties. That will work locally. But anyplace you want to deploy it to you'll need to register the wrapper and compile the .net dll via regasm. Search the forum for regasm, the instructions have been posted a few times.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top