Creating a Dll(asembly dynamically) + vb.net


CREATING DLL DYNAMICALLY
you need to complie this code
Public Function CreateResourceAssembly() As Boolean
        Dim currentpageHashVal As Hashtable = New Hashtable()
        Dim intArrIndx As Integer
        Dim strTextVal As String
        Dim blnIsSuccess As Boolean
        Dim strAsmFileName As String = FetchTest.resources.dll
        Dim strPathAssmbly As String = strAppPath + FetchTest.resources.dll"
 
        Dim appdomain As AppDomain = Thread.GetDomain()
        Dim asmName As New AssemblyName()
        Dim strVersion As String = Nothing
        Dim strKey As String = Nothing
        Dim hashResPage As Hashtable = New Hashtable()
        Dim ItemEnumeratorPage As System.Collections.IDictionaryEnumerator
        Dim blnIdExist As Boolean = False
 
        asmName.Name = Wpms.resources.dl
 
        Dim resourceName As String = Wpms.resources"
        asmName.CodeBase = strPath
        Dim strDate As String
        strDate = Date.Now.ToString("dd/MM/yyyy").Replace("/""")
        intBuild = CType(strDate, Integer)
        intRev = intRev + 1
        strVersion = "1.0.0" & "." & CType(intRev, String)
        asmName.Version = New Version(1, 0, 0, intRev)
        asmName.CultureInfo = New CultureInfo(strLang)
 
        Dim asmBuilder As AssemblyBuilder = appdomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave, strPath)
        Dim modulebuilder As ModuleBuilder = asmBuilder.DefineDynamicModule(strAsmFileName, strAsmFileName)
        Dim resWriter As System.Resources.IResourceWriter
        Dim blnGenEngRes As Boolean = True
        resWriter = modulebuilder.DefineResource(resourceName, "MyDescription", ResourceAttributes.Public)
 
‘ writing in resource file below is a n example ….
   Dim ItemEnumerator As System.Collections.IDictionaryEnumerator
ItemEnumerator = resHastable.GetEnumerator()
   Do While ItemEnumerator.MoveNext
                    resWriter.AddResource(CType(ItemEnumerator.Key, String), CType(ItemEnumerator.Value, String))
                Loop
 
                asmBuilder.Save(strAsmFileName) ‘ SAVING ASSEMBLY
Return blnIsSuccess
 
End Function

0 comments:

Post a Comment