【问题标题】:Program will run in debug mode but will not run once published程序将以调试模式运行,但一旦发布就不会运行
【发布时间】:2013-03-13 23:28:57
【问题描述】:

由于某种原因,我现在尝试在 VB 2010 中制作的任何程序都将在 Visual Basic 的调试模式下运行,但一旦我将其发布到我的计算机上就不会运行,我们将不胜感激。

代码以备不时之需。

主窗体:

Public Class Form1
Dim locat As String = System.Reflection.Assembly.GetEntryAssembly.Location
Dim MyDirectory As String = System.IO.Path.GetDirectoryName(locat)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim sfile As String
    Dim rfile As String
    sfile = IO.Directory.GetCurrentDirectory + "\Games\" + ListBox1.SelectedItem.ToString
    rfile = ListBox1.SelectedItem.ToString
    My.Computer.FileSystem.DeleteFile(sfile)
    ListBox1.Items.Remove(rfile)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim ddir As String
    ddir = My.Computer.FileSystem.CurrentDirectory + "\Games\"
    ListBox1.Items.Clear()
    My.Computer.FileSystem.DeleteDirectory(ddir, FileIO.DeleteDirectoryOption.DeleteAllContents)
    My.Computer.FileSystem.CreateDirectory(Application.StartupPath & "\Games\")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If IO.File.Exists(MyDirectory + "\" + Me.ProductName + ".old") Then
        IO.File.Delete(MyDirectory + "\" + Me.ProductName + ".old")
    End If

    Dim dir As New IO.DirectoryInfo(Application.StartupPath & "/Games/")
    Dim files As IO.FileInfo() = dir.GetFiles("*.swf")
    Dim fileName As IO.FileInfo
    For Each fileName In files
        ListBox1.Items.Add(fileName.Name)
    Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    AxShockwaveFlash1.Movie = Application.StartupPath & "\Games\" & ListBox1.SelectedItem.ToString()
End Sub

Private Sub AddGamesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddGamesToolStripMenuItem.Click
    Dim gd As New OpenFileDialog
    Dim dir As String
    dir = Application.StartupPath & "\Games\"
    gd.Title = "Pick a game to add to the game list"
    gd.Filter = "Shockwave Flash File (*.swf)|*.swf"
    gd.ShowDialog()
    ListBox1.Items.Add(gd.SafeFileName)
    My.Computer.FileSystem.CopyFile(gd.FileName, dir & gd.SafeFileName)
End Sub

Private Sub RefreshGameListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshGameListToolStripMenuItem.Click
    ListBox1.Items.Clear()
    Dim dir As New IO.DirectoryInfo(Application.StartupPath & "/Games/")
    Dim files As IO.FileInfo() = dir.GetFiles("*.swf")
    Dim fileName As IO.FileInfo
    For Each fileName In files
        ListBox1.Items.Add(fileName.Name)
    Next
End Sub

Private Sub RemoveGamesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveGamesToolStripMenuItem.Click
    Button2.PerformClick()
End Sub

Private Sub CheckForUpdateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdateToolStripMenuItem.Click
    Updates.Show()
End Sub
End Class

更新表格:

Imports System.IO
Imports System.Net

Public Class Updates
Dim locat As String = System.Reflection.Assembly.GetEntryAssembly.Location
Dim MyDirectory As String = System.IO.Path.GetDirectoryName(locat)
Public totalsize As String
Public link As String
Public Csize As String
Public amount As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    My.Computer.FileSystem.RenameFile(MyDirectory + "\" + Me.ProductName + ".exe", Me.ProductName + ".old")
    Timer1.Start()
    BackgroundWorker1.RunWorkerAsync()
    Button1.Enabled = False
End Sub

Private Sub Updates_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Label3.Text = Me.ProductVersion
    Try
        Dim instance As WebClient = New WebClient
        Dim address As String = "https://dl.dropbox.com/u/119965245/XtroPlayer_Version.txt"
        Dim returnValue As String
        returnValue = instance.DownloadString(address)
        Label4.Text = returnValue
        If Not Label4.Text >= Label3.Text Then
        Else
            Button1.Enabled = True
        End If
    Catch ex As Exception

    End Try
    Control.CheckForIllegalCrossThreadCalls = False
End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    Try
        link = "https://dl.dropbox.com/u/119965245/Xtro%20Player.exe"
        Dim size1 As Integer
        Dim wr As WebRequest
        wr = WebRequest.Create(link)
        Dim webr As WebResponse = wr.GetResponse
        size1 = webr.ContentLength
        webr.Close()
        size1 = size1 / 1024
        ProgressBar1.Maximum = size1
        totalsize = size1
        My.Computer.Network.DownloadFile("https://dl.dropbox.com/u/119965245/Xtro%20Player.exe", MyDirectory + "\" + Me.ProductName + ".exe")
    Catch ex As Exception

    End Try
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If File.Exists(MyDirectory + "\" + Me.ProductName + ".exe") Then
        Dim o As New FileInfo(MyDirectory + "\" + Me.ProductName + ".exe")
        amount = o.Length
        amount = amount / 1024
        Csize = amount
        ProgressBar1.Value = amount
    End If
    Label1.Text = Csize + " kbs / " + totalsize + " kbs"
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    Try
        Shell(MyDirectory + "\" + Me.ProductName + ".exe")
        Me.Close()
    Catch ex As Exception

    End Try
End Sub
End Class

我对它所做的唯一另一件事是更改程序集信息的标题、公司、产品、版权和版本信息。

【问题讨论】:

  • 当你说它“不运行”时,会发生什么?你有错误吗?如果是这样,与该错误相关的消息是什么?我现在手头没有 VB.NET 编译器,所以无法尝试您的示例代码。
  • 嗯,它是在Visual Basic中完成的,但基本上它不会打开,即使我在兼容模式下运行它也不会出现错误。
  • 检查所有引用是否都有“本地副本”。

标签: vb.net visual-studio


【解决方案1】:

尝试检查您的 /Games/ 参考资料;其中一些似乎将斜线反转。

【讨论】:

  • 如果您在谈论文件路径,这不太可能是问题所在。 Windows API 在斜杠方面非常多元:它们可以很好地处理反斜杠和斜杠。
猜你喜欢
  • 1970-01-01
  • 2019-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多