BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
StoneCat
Fluorite | Level 6

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

4 REPLIES 4
AndreasMenrath
Pyrite | Level 9

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.

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
StoneCat
Fluorite | Level 6

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.

ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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