Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Run VB.net Code in PowerShell

$
0
0

I have been looking through the web and saw that you can take C# and make it usable in Windows Powershell. I was able to create a test with vb.net and get it to work but now when I try and use a thrid party component I cant get it to work. Im having issues getting the vb.net code to see the third part dll information. Below are the errors and my current code, Im using Qios DevSuite for the custom controls. If someone can show me what Im doing wrong or can point me in the right direction that would be great.

PS C:\Users\shuppz> C:\Users\shuppz\Desktop\FormTest.ps1
GAC    Version        Location                                                                                                                                                                                  
---    -------        --------                                                                                                                                                                                  
False  v2.0.50727     E:\11252013\Desktop\Random Stuff\Admin Launcher 1.0\Source\Qios.DevSuite.Components.dll                                                                                                   
New-Object : Cannot find type [Qios.DevSuite.Components]: make sure the assembly containing this type is loaded.
At C:\Users\shuppz\Desktop\FormTest.ps1:71 char:24+ $MyCompObj = New-Object <<<<  Qios.DevSuite.Components+ CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Add-Type : Cannot bind parameter 'ReferencedAssemblies' to the target. Exception setting "ReferencedAssemblies": "Value cannot be null.
Parameter name: assemblyString"
At C:\Users\shuppz\Desktop\FormTest.ps1:89 char:81+     Add-Type -TypeDefinition $form -Language 'VisualBasic' -ReferencedAssemblies <<<<  $Assemblies -IgnoreWarnings+ CategoryInfo          : WriteError: (:) [Add-Type], ParameterBindingException+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.AddTypeCommand
You cannot call a method on a null-valued expression.
At C:\Users\shuppz\Desktop\FormTest.ps1:93 char:12+ $form1.Show <<<< () | Out-Null+ CategoryInfo          : InvalidOperation: (Show:String) [], RuntimeException+ FullyQualifiedErrorId : InvokeMethodOnNull

My Code:

$form = @" Imports System Imports System.Windows.Forms

Public Class frmMain Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list.<System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.QButton1 = New Qios.DevSuite.Components.QButton() Me.SuspendLayout() ' 'QButton1 ' Me.QButton1.Image = Nothing Me.QButton1.Location = New System.Drawing.Point(13, 13) Me.QButton1.Name = "QButton1" Me.QButton1.Size = New System.Drawing.Size(160, 23) Me.QButton1.TabIndex = 0 Me.QButton1.Text = "Test!!!!" ' 'frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(185, 50) Me.Controls.Add(Me.QButton1) Me.Name = "frmMain" Me.ShowIcon = False Me.ResumeLayout(False) End Sub Friend WithEvents QButton1 As Qios.DevSuite.Components.QButton Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Private Sub QButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QButton1.Click MsgBox("THis is a test of powershell and VB.net and QIOS") End Sub End Class"@ #load 3rd party dll [System.Reflection.Assembly]::LoadFrom("E:\11252013\Desktop\Random Stuff\Admin Launcher 1.0\Source\Qios.DevSuite.Components.dll") $MyCompObj = New-Object Qios.DevSuite.Components $Assemblies = @( 'System.Windows.Forms', 'System.Drawing', 'System.Data', 'System.Xml', 'System.ServiceProcess', 'System.Core', $MyCompObj ) if($form1 -ne $null){$form1.Dispose()} try{$form1 = New-Object 'Form1'} catch { Add-Type -TypeDefinition $form -Language 'VisualBasic' -ReferencedAssemblies $Assemblies -IgnoreWarnings $form1 = New-Object 'Form1' } $form1.Show() | Out-Null



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>