The following code works fine in VS but when I try loading via WinBatch it tells me that it cannot load Renci.SshNet file or assembly because it cannot find the file. I have tried using the full path but that didn't help in the reference. Adding "using" statements for it doesn't help either. Suggestions?
Thanks.
Jim
cSharp = $"
namespace c_browser
{
using System;
using System.Data;
using MySql.Data.MySqlClient;
public class Program
{
public void DB_Connect()
{
string connstring = "server=localhost; port=3306; database=xxxxxxxxxx; UID=xxxxx; password=xxxxxxxx";
MySqlConnection myConn = new MySqlConnection(connstring);
try
{
myConn.Open();
string web_login = "Y";
string sql = "SELECT isbn, title FROM resources where buy_status = 'BROWSE' and isbn like '97%%' and Length(isbn) = 13;";
MySqlCommand cmd = new MySqlCommand(sql, myConn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string isbn = rdr[0].ToString();
// MessageBox.Show(isbn);
}
rdr.Close();
}
catch (Exception ex)
{
// MessageBox.Show(ex.ToString());
}
myConn.Close();
}
}
}
$"
;message("HEY",cSharp)
GoSub LOAD_ROUTINE
Load_WebBrowser()
oSample = ObjectClrNew( 'c_browser.Program' )
oSample.DB_Connect()
Exit
:LOAD_ROUTINE
#DefineSubRoutine Load_WebBrowser()
;***************************************************************************
;** Run C# in memory using WinBatch - Use Namespace.Class defined in CSharpeSource
;**
;** Purpose: Run C# in memory using WinBatch - Using Namespace.Class defined in CSharpeSource
;** Inputs:
;** Outputs: Results in message
;**
;** Developer: Deana Falk 2014.04.14
;***************************************************************************
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; mscorlib assembly is automatically loaded by WinBatch when the CLR is loaded.
; ObjectClrOption ('use','mscorlib, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
ObjectClrOption ( 'useany', 'System')
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Compiles the c# code in Memory
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objCSharp = ObjectClrNew('Microsoft.CSharp.CSharpCodeProvider')
objParams = ObjectClrNew('System.CodeDom.Compiler.CompilerParameters')
objParams.GenerateInMemory = ObjectType( "VT_BOOL", 1 ) ;TRUE
objParams.ReferencedAssemblies.Add("System.dll")
objParams.ReferencedAssemblies.Add("System.Data.dll")
objParams.ReferencedAssemblies.Add("Mysql.Data.dll")
objParams.ReferencedAssemblies.Add("Renci.SshNet.dll")
objParams.ReferencedAssemblies.Add("System.Security.dll")
;objParams.ReferencedAssemblies.Add("")
objResult = objCSharp.CompileAssemblyFromSource(objParams,cSharp)
;Compiler Output
If objResult.Output.Count > 0 Then
strOutput = ''
For x = 0 to objResult.Output.Count-1
If strOutput == "" Then
strOutput = objResult.Output.Item(x)
Else
strOutput = strOutput:@LF:objResult.Output.Item(x)
EndIf
Next
Pause('Compiler Output',strOutput)
Endif
; Compiler Errors
If objResult.Errors.Count > 0 Then
strErrors = ''
ForEach ce In objResult.Errors
;Pause("Error", ce.ToString())
If strErrors == "" Then
strErrors = ce.ToString()
Else
strErrors = strErrors:@LF:ce.ToString()
EndIf
Next
Pause('Compiler Errors',strErrors)
Exit
EndIf
#EndSubRoutine
Return