We had a ASP.NET 1.1 Windows app that had the code below that I'm now trying to implement in ASP.NET 2.0 Windows app. The problem is that Main is "not found". The idea behind this is that it checks to see if the server has a new version and, if it does, it downloads it to the client computer and updates it. Can't figure out what I'm doing wrong... I get the error at the first Try / Catch at typeContent.InvokeMember. The error message is "Method 'Example.My.MyApplication.Main' not found."
Thanks,
Dan
Thanks,
Dan
VB.NET:
Imports System.Reflection
Imports System.Security
Imports System.Security.Policy
Public Class Utility
Friend Shared Sub CheckForNewVersion()
Dim assemblyContent As System.Reflection.Assembly = Nothing
Dim strURL As String = "http://www.example.com/example/example.exe"
Try
assemblyContent = System.Reflection.Assembly.LoadFrom(strURL)
Dim Version As String
Version = Replace(assemblyContent.FullName, Microsoft.VisualBasic.Left(assemblyContent.FullName, assemblyContent.FullName.LastIndexOf("Version=")), "")
Version = Microsoft.VisualBasic.Left(Version, Version.LastIndexOf(", Culture="))
Version = Replace(Version, "Version=", "")
If My.Application.Info.Version.ToString <> Version Then
Dim typeContent As System.Type
typeContent = assemblyContent.EntryPoint.ReflectedType()
Try
typeContent.InvokeMember("Main", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.InvokeMethod Or BindingFlags.Static, Nothing, Nothing, Nothing)
Catch ex As Exception
SetSecurity(assemblyContent.Location.ToString)
Try
typeContent.InvokeMember("Main", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.InvokeMethod Or BindingFlags.Static, Nothing, Nothing, Nothing)
Catch exp As Exception
WriteToEventLog("Invoking Main(): " & exp.ToString, EventLogEntryType.Error)
'End
End Try
End Try
Try
System.IO.File.Delete(assemblyContent.Location.ToString)
Catch ex As Exception
End Try
End If
Catch ex As Exception
End Try
End Sub
Private Shared Sub SetSecurity(ByVal Location As String)
' Irrelevant code here
End Sub
End Class
Last edited: