Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:19:01+00:00 2026-05-25T16:19:01+00:00

I have a VB.NET project in Visual Studio 2008 that I created a specialized

  • 0

I have a VB.NET project in Visual Studio 2008 that I created a specialized addin for. The addin prompts the user to select a database table, takes a template form class’s files, copies them to another directory within the project, and renames the form class within the copied files. It then opens the new form and adds controls to it based on the fields in the database table.

The copying of the template form causes the background compiler to give ‘duplicate member’ errors, such as “Private Sub InitializeComponents(…) has multiple definitions with identical signatures,” even though I renamed the files of the new form and the class name within them. Sometimes these errors go away before the new form is opened, but when they stick around the new form doesn’t open correctly, and it throws an error instead.

I implemented some code to wait until there are zero errors in the error list before trying to open the new form. This has helped sometimes, but for some reason sometimes the errors don’t go away at all until the addin is closed.

I was hoping someone could give tips on how to copy the template form and rename the copy without the background compiler ever noticing duplicate members. If that’s not possible, then perhaps someone has an alternative?

Here is my code that copies and renames the template form:

Private Sub CreateDataForm(ByVal tableName As String, ByVal displayName As String) ', ByVal subDataForms As IList(Of Object))
    Try
        Dim dataFormClassName As String = "frm" & MakeValidName(displayName)
        Dim dataFormFileName As String = dataFormClassName & cVBSuffix
        Dim templateFileName As String = DataFormTemplate.Name
        Dim templateClassName As String = Replace(templateFileName, cVBSuffix, String.Empty)

        'copy form template to data forms folder
        'copy files associated with main projectitem
        Dim newPItem As ProjectItem = Nothing

        For i As Integer = 1 To DataFormTemplate.FileCount
            newPItem = DataFormsFolder.ProjectItems.AddFromFileCopy(DataFormTemplate.FileNames(CShort(i)))
        Next

        'copy files associated with sub projectitems
        For Each item As ProjectItem In DataFormTemplate.ProjectItems
            For i As Integer = 1 To item.FileCount
                DataFormsFolder.ProjectItems.AddFromFileCopy(item.FileNames(CShort(i)))
            Next
        Next

        newPItem.Name = dataFormFileName

        newPItem.ContainingProject.Save()

        'fix class name for dataform template
        FixDataFormClassName(DataFormTemplate, dataFormClassName, templateClassName)

        newPItem.ContainingProject.Save()

        Application.DoEvents()

        'get table metadata
        Dim lGetColumnInfo As DataColumnCollection = GetColumnInfo(tableName)


        'add field controls
        ConvertColumnInfoToFormControls(newPItem, lGetColumnInfo, tableName, displayName)

    Catch ex As Exception
        DisplayExceptionMessage(ex)
    End Try
End Sub

Private Shared Sub FixDataFormClassName(ByVal pItem As ProjectItem, ByVal dataFormClassName As String, ByVal templateClassName As String)
    If pItem.Document IsNot Nothing Then
        pItem.Document.Close(vsSaveChanges.vsSaveChangesPrompt)
    End If
    For i As Integer = 1 To pItem.FileCount
        Dim dftFile As New IO.FileInfo(pItem.FileNames(CShort(i)))
        Dim tr As IO.TextReader = dftFile.OpenText() 'IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
        Dim sb As New Text.StringBuilder
        Dim newData As String = tr.ReadToEnd().Replace(dataFormClassName, templateClassName)
        tr.Close()
        Dim sw As New IO.StreamWriter(dftFile.FullName)
        sw.Write(newData)
        sw.Close()
    Next

    If pItem.FileCodeModel IsNot Nothing Then CType(pItem.FileCodeModel, FileCodeModel2).Synchronize()

    For Each item As ProjectItem In pItem.ProjectItems
        FixDataFormClassName(item, dataFormClassName, templateClassName)
    Next
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:19:02+00:00Added an answer on May 25, 2026 at 4:19 pm

    After all my attempts at correcting this via Visual Studio’s Extensibility API, I gave up with that approach and now do all the dirty work behind the scenes. I take the template form’s files, copy them to the new directory, and change their file names and contents all behind the scenes via FileInfo objects and whatnot before I add the new files to the project. This way, VS is never in a state where there are ‘duplicate member’ errors.

    If anyone ever wants to see the code, holler and I’ll post it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a visual studio 2008 solution that includes an asp.net-hosted remoting project in
I have created a custom control using VB.NET in Visual Studio 2008 that gives
Now that I have built a database. Visual Studio 2008 SP1’s ADO.NET Entity Framework
I have a basic ASP.Net project created in Visual Studio 2008 on Windows Server
I have created a Windows Forms Application project by Visual Studio.Net 2008. In order
I have a WPF VB.NET project in Visual Studio 2008. For some reason, Visual
I have a C# .NET Compact Framework 3.5 mobile project in Visual Studio 2008.
Hi I have a Visual Studio solution and an ASP.NET MVC project that uses
In visual studio, I have an asp.net 3.5 project that is using MS Enterprise
I have Visual Studio 2008 and ASP.NET MVC2 project. To App_data folder I added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.