WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ObjectClrOption

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Rules for Using Appbase

 Keywords: ObjClrOption AppBase Loadfrom SQLite Assembly DLL CLR Powershell  

Question:

How would I translate [System.Reflection.Assembly]::LoadFrom("C:\Powershell\System.Data.SQLite.dll") in WB CLR code, so that I might continue with a script like
ObjectClrOption("use", "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
cn = ObjectClrNew("System.Data.SQLite.SQLiteConnection")
cn.ConnectionString = "Data Source=E:\RA\SQLITE\SMS.SQLITE"
cn.Open()

cm = ObjectClrNew("System.Data.SQLite.SQLiteCommand")
cSQL = "SELECT SMS, Carrier FROM Carriers"
cm.Connection = cn
cm.CommandText = cSQL
dr = cm.ExecuteReader()

Answer:

Two simple rules to remember. The 'appbase' option sets the directory that the CLR will use to look for 'non-GAC' assemblies. The CLR does not use path environment variable searches like traditional Windows applications and DLLs often do. If you want to use 'non-GAC' assembles, you must either place those assemblies in the directory containing the WIL interpreter DLL or you must use the 'appbase' option. So you can do the following
ObjectClrOption("AppBase", "C:\Powershell")
The second rule is that for what I hope are obvious reasons WinBath does not automagically load assemblies into the AppDomain of your script. The only exception is the 'mscorlib' assembly which the CLR automatically loads when it is loaded into a process. You use the 'use' option to load assemblies into your WinBatch script AppDomain so you need the following before you can make use of your assembly's classes.
ObjectClrOption("use","System.Data.SQLite")
Together these statements are equivalent to your Powershell "[System.Reflection.Assembly]::LoadFrom("C:\Powershell\System.Data.SQLite.dll")" line.

The SQLite assembly works well in WinBatch. In fact, we use it as part of the CLR subsystem regression test.


Article ID:   W17805
Filename:   Rules for Using Appbase.txt
File Created: 2014:01:06:10:00:26
Last Updated: 2014:01:06:10:00:26