I was working my way thru the paper 016-2007 to understand how to build OLE automation C# applications over my SAS Enterprise guide projects. I use Visual Studio C# Enterprise 2015 and SAS Enterprise Guide 7.1
I tried compiling the following piece of C# code
using System; namespace test { class test { static void Main(string[] args) { SAS.EG.Scripting.Application EGApp = new SAS.EG.Scripting.Application(); SAS.EG.Scripting.Project EGProject = EGApp.Open("E:\\SASDocuments\\EGProjectTest.egp",""); //Close the project EGProject.Close(); //Exit the application EGApp.Quit(); } } }
and got the following error.
Error CS0266 Cannot implicitly convert type 'SAS.EG.Scripting.ISASEGProject' to 'SAS.EG.Scripting.Project'. An explicit conversion exists (are you missing a cast?)
If Scripting.ISASEGProject is an interface to Scripting.Project why does it complain? Please help.
"EGPSearch" is the root name of the example searcher project that I shared in that SAS Global Forum paper, and so its resources should be part of the EXE that you're building -- unless you've altered the name. Something seems to be out of sync. If you're adapting my example by modifying it in place, maybe a better approach is to create a new project from scratch and add in just the references that you need.
Check this more modern blog post and paper on the topic of SAS Enterprise Guide automation. It points to a more complete .NET example that might help.
Here's a direct link to the paper.
Chris
Chris,
Many thanks. I see that the AssembylResolver code points to the 4.3 installation of SAS Enterprise guide. Compilation succeeds but execution fails citing a System.IO.FileNotFoundException. Possibly this is because I have SAS Enterprise guide 7.1 installed instead of 4.3. I then looked into the registry for the equivalent 7.1 installation and surprisingly I dont find any installation of 7.1 as per the path below, root being HKEY_LOCAL_MACHINE
"SOFTWARE\SAS Institute Inc.\Enterprise Guide\4.3"
There must be some issue with my SAS Enterprise Guide 7.1 (32-bit) installation right?
Make sure that you're looking in the proper registry location. 64-bit Windows has two registries: a 32-bit version and a 64-bit version. If you have EG 32-bit, then you want to make sure that you are building your .NET application as a 32-bit (x86 architecture) application.
A 32-bit EG key will be in:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SAS Institute Inc.\Enterprise Guide\7.1
Chris
Ok. I do see the installation in the key you mentioned. I now modifed the SEG43AssemblyResolver.cs file to the following. I still get an System.IO.FileNotFoundException exception though. I have also posted the exception details below the code (it seems to refer to some file FileName=C:\Program Files (x86)\SASHome\EnterpriseGuide\7.1\EGPSearch43.resources.dll which does not exist
using System; using System.IO; using System.Reflection; using Microsoft.Win32; namespace SAS.EG.Automation { /// <summary> /// Class to help you use SAS Enterprise Guide classes from their installed location /// </summary> public class SEG43AssemblyResolver { #region internal members // these are the default install paths for our 4.3/9.2 products //internal static string PathToEGuideInstall = @"C:\Program Files\SAS\EnterpriseGuide\4.3"; internal static string PathToEGuideInstall = @"C:\Program Files (x86)\SASHome\EnterpriseGuide\7.1"; #endregion /// <summary> /// Install the AssemblyResolver event listener and discover locations of installed assemblies /// </summary> /// <exception cref="System.IO.FileNotFoundException">Thrown when unable to locate the SAS Enterprise Guide 4.3 installed location.</exception> public static void Install() { // initialize EG path RegistryKey regKey = null; try { // determine EG 4.3 location using InstallShield key //using (regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\SAS Institute Inc.\Enterprise Guide\4.3", false)) using (regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\SAS Institute Inc.\Enterprise Guide\7.1", false)) { if ((regKey != null) && (regKey.GetValue("InstallLocation") != null)) { string path = regKey.GetValue("InstallLocation") as string; if (path.Length > 0) PathToEGuideInstall = path; } else throw new System.IO.FileNotFoundException("Cannot locate SAS Enterprise Guide 7.1. Is SAS Enterprise Guide 7.1 installed?"); } } catch { throw new System.IO.FileNotFoundException("Cannot locate SAS Enterprise Guide 7.1. Is SAS Enterprise Guide 7.1 installed?"); } // install Assembly Resolver event AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve); } /// <summary> /// Resolve assemblies not found in the current directory /// </summary> /// <param name="sender">Sender of event</param> /// <param name="args">contains a Name property with the assembly name needed</param> /// <returns>Loaded assembly, loaded by this routine</returns> private static Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { string resolvepath; // all files that are "early bound" should be in the Enterprise Guide directory resolvepath = PathToEGuideInstall; string[] name = args.Name.Split(','); string path = System.IO.Path.Combine(resolvepath, name[0] + ".dll"); try { Assembly foundAssembly = Assembly.LoadFile(path); return foundAssembly; } catch (System.IO.FileNotFoundException ex) { throw new System.IO.FileNotFoundException("Could not load assembly from expected location", path, ex); } } } }
Also posting the exception message behind the System.IO.FileNotFoundException
System.IO.FileNotFoundException was unhandled FileName=EGPSearch43.resources, Version=4.3.0.0, Culture=en-US, PublicKeyToken=null FusionLog="" HResult=-2147024894 Message=Could not load file or assembly 'EGPSearch43.resources, Version=4.3.0.0, Culture=en-US, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Source=mscorlib StackTrace: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark) at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark) at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream) at System.Resources.ResourceManager.GetObject(String name) at EGPSearch.MainSearchWindow.InitializeComponent() in E:\SASDocuments\EGPSearch_Sample\EGPSearch_src\Core\MainSearchWindow.Designer.cs:line 278 at EGPSearch.MainSearchWindow..ctor(String version) in E:\SASDocuments\EGPSearch_Sample\EGPSearch_src\Core\MainSearchWindow.cs:line 38 at EGPSearch.Program.Main() in E:\SASDocuments\EGPSearch_Sample\EGPSearch_src\43\Program.cs:line 48 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: FileName=C:\Program Files (x86)\SASHome\EnterpriseGuide\7.1\EGPSearch43.resources.dll HResult=-2147024894 Message=Could not load assembly from expected location Source=EGPSearch43 StackTrace: at SAS.EG.Automation.SEG43AssemblyResolver.currentDomain_AssemblyResolve(Object sender, ResolveEventArgs args) in E:\SASDocuments\EGPSearch_Sample\EGPSearch_src\43\SEG43AssemblyResolver.cs:line 75 at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName) InnerException: HResult=-2147024894 Message=The system cannot find the file specified. (Exception from HRESULT: 0x80070002) Source=mscorlib StackTrace: at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence) at System.Reflection.Assembly.LoadFile(String path) at SAS.EG.Automation.SEG43AssemblyResolver.currentDomain_AssemblyResolve(Object sender, ResolveEventArgs args) in E:\SASDocuments\EGPSearch_Sample\EGPSearch_src\43\SEG43AssemblyResolver.cs:line 70 InnerException:
"EGPSearch" is the root name of the example searcher project that I shared in that SAS Global Forum paper, and so its resources should be part of the EXE that you're building -- unless you've altered the name. Something seems to be out of sync. If you're adapting my example by modifying it in place, maybe a better approach is to create a new project from scratch and add in just the references that you need.
Chris, thanks. I get it to compile and run without it crashing using only the AssemblyResolver installation code. I would have to reproduce the UI code to check whether the querying part works. Will close this discussion for now with many thanks for your support .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.