Hello community,
i would like to automate the creation of a SAS 7.1 project and decided to use a C # program.
After I had inserted the SASEGScripting.dll as a reference, I was able to do a lot with the SAS EG 7.1.
However, I always get the error message when executing the following code section:
public static SAS.EG.Scripting.Application EGApp { get; private set; } public static SAS.EG.Scripting.ISASEGProject EGProject { get; private set; } EGProject = EGApp.Open(projectPath, password); //Error
If I want to open a project via the code, the following error message occurs:
System.TypeInitializationException: Der Typeninitialisierer für "LibGit2Sharp.Core.NativeMethods" hat eine Ausnahme verursacht. ---> System.DllNotFoundException: Die DLL "git2-e0902fb": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden. bei LibGit2Sharp.Core.NativeMethods.git_libgit2_init() bei LibGit2Sharp.Core.NativeMethods.LibraryLifetimeObject..ctor() bei LibGit2Sharp.Core.NativeMethods..cctor() --- End of inner exception stack trace --- bei LibGit2Sharp.Core.NativeMethods.git_repository_init_ext(RepositorySafeHandle& repository, FilePath path, GitRepositoryInitOptions options) bei LibGit2Sharp.Core.Proxy.git_repository_init_ext(FilePath workdirPath, FilePath gitdirPath, Boolean isBare) bei LibGit2Sharp.Repository.Init(String path, Boolean isBare) bei SAS.EG.ProjectElements.InternalGitRepository..ctor(ProjectCollection pc) bei SAS.EG.ProjectElements.ProjectCollection..ctor(IMetadataService metadataService) bei SAS.EG.ProjectElements.ProjectCollection..ctor() bei SAS.EG.Scripting.Project..ctor() bei SAS.EG.Scripting.Application.Open(String fileName, String password)
Many thanks for the support!
You can use an Assembly Resolver class/event to load the DLLs from the EG install as needed.
Add a class like this:
/// <summary> /// Class to help you use SAS Enterprise Guide classes from their installed location /// </summary> public class SEG71AssemblyResolver { #region internal members internal static string PathToEGuideInstall = @"C:\Program Files\SAS\EnterpriseGuide\7.1"; #endregion /// <summary> /// Install the AssemblyResolver event listener and discover locations of installed assemblies /// </summary> public static void Install(string path) { PathToEGuideInstall = path; // 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[] name = args.Name.Split(','); string path = System.IO.Path.Combine(PathToEGuideInstall, name[0] + ".dll"); try { Assembly foundAssembly = Assembly.LoadFile(path); return foundAssembly; } catch (System.IO.FileNotFoundException) { return null; } } }
Then "install" this handler in the Main() function for your app:
SAS.EG.Automation.SEG71AssemblyResolver.Install(EGinstall);
Passing in the path where EG is installed on your system. This class *should* direct the .NET runtime to load any assembly it needs from the installed app folder.
Well, it looks like EG cannot load a required DLL -->
System.DllNotFoundException: Die DLL "git2-e0902fb"
I have the DLL file "git2-e0902fb.dll" in the root directory of Enterprise Guide.
Just add that DLL to your application and it should work.
I agree with @AndreasMenrath -- adding that DLL to your app should do the trick. This dependency was introduced in 7.11 with the addition of Program History (which relies on an internal git repository).
I have added the reference in the project, but I get the same error message.
I have put my entire SAS Enterprise Guide folder into the / bin / debug folder of my program, now it works.
Do you know which of the files the git2-e0902fb-reference needs, so I do not have to deliver the whole folder?
Thanks.
You can use an Assembly Resolver class/event to load the DLLs from the EG install as needed.
Add a class like this:
/// <summary> /// Class to help you use SAS Enterprise Guide classes from their installed location /// </summary> public class SEG71AssemblyResolver { #region internal members internal static string PathToEGuideInstall = @"C:\Program Files\SAS\EnterpriseGuide\7.1"; #endregion /// <summary> /// Install the AssemblyResolver event listener and discover locations of installed assemblies /// </summary> public static void Install(string path) { PathToEGuideInstall = path; // 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[] name = args.Name.Split(','); string path = System.IO.Path.Combine(PathToEGuideInstall, name[0] + ".dll"); try { Assembly foundAssembly = Assembly.LoadFile(path); return foundAssembly; } catch (System.IO.FileNotFoundException) { return null; } } }
Then "install" this handler in the Main() function for your app:
SAS.EG.Automation.SEG71AssemblyResolver.Install(EGinstall);
Passing in the path where EG is installed on your system. This class *should* direct the .NET runtime to load any assembly it needs from the installed app folder.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.