Desktop productivity for business analysts and programmers

Failure in running c# code SAS EG 7.1

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Failure in running c# code SAS EG 7.1

[ Edited ]

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!

 


Accepted Solutions
Solution
‎11-24-2016 04:32 AM
Community Manager
Posts: 2,712

Re: Failure in running c# code SAS EG 7.1

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.

View solution in original post


All Replies
Frequent Contributor
Posts: 118

Re: Failure in running c# code SAS EG 7.1

[ Edited ]

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.

Community Manager
Posts: 2,712

Re: Failure in running c# code SAS EG 7.1

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).

Occasional Contributor
Posts: 8

Re: Failure in running c# code SAS EG 7.1

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.

Solution
‎11-24-2016 04:32 AM
Community Manager
Posts: 2,712

Re: Failure in running c# code SAS EG 7.1

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 728 views
  • 1 like
  • 3 in conversation