Desktop productivity for business analysts and programmers

Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)

I am using SAS Enterprise Guide 7.12 HF3 (7.100.2.3444) (64-bit)

 

I have a SAS file called CalculateLoad.egp which just imports some CSV files, grabs some data from a Windows SQL Server, does a few calculations and spits out a CSV file.

 

I wanted to run CalculateLoad.egp several times via automation. I wanted to use Excel VBA to let the user run the CalculateLoad.egp many many times.

 

I have been following this document (http://support.sas.com/resources/papers/proceedings12/298-2012.pdf) that tells me how to use Excel VBA to automate a SAS Program.

 

For reference, the relevant VBA code is below (its on Page 6 of the document):

 

Option Explicit ' Forces us to declare all variables

Dim Application ' Application

Dim Project ' Project object

Dim sasProgram ' Code object (SAS program)

Dim n ' counter

 

Set Application = CreateObject("SASEGObjectModel.Application.4.3")

' Set to your metadata profile name, or "Null Provider" for just Local server

Application.SetActiveProfile("My Server")

' Create a new Project

Set Project = Application.New ' add a new code object to the Project

Set sasProgram = Project.CodeCollection.Add

 

The code I am trying to write is as follows:

 

Public Application
Public Project
Public sasProgram

Sub Example2()

    Set Application = CreateObject("SASEGObjectModel.Application.7.1")

    Set Project = Application.New   ' <<<<------- ERROR OCCURING HERE

End sub

 

The error message I am getting is:

 

Run-time error '-2146233036 (80131534)': The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.

 

I also get this error if I try: Set Project = Application.Open("c:\myprojects\project.egp", "")

 

I would appreciate some guidance.... Thanks....

 

Some additional background information (just in case it is relevant):

 

When SAS was first installed I couldn't even execute: Set Application = CreateObject("SASEGObjectModel.Application.7.1").

 

I got the following error message from VBA:

 

Run-time error '429': ActiveX component can't create object

 

From Googling, I ran the following from command prompt:

 

RegASM.exe /tlbSmiley FrustratedASEGScripting.tlb /codebase “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.dll

 

and then

 

RegTypeLib.exe “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.tlb”

 

So now VBA happliy executes Set Application = CreateObject("SASEGObjectModel.Application.7.1")

 

But it doesn't like Set Project = Application.New or Set Project = Application.Open("c:\myprojects\project.egp", "")

 

Would appreciate it if someone knows how to fix it. Thanks.

 


Accepted Solutions
Solution
‎03-21-2017 07:17 PM
Community Manager
Posts: 2,889

Re: Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)

I'm afraid that the exception is caused by using 32-bit Excel to automate a 64-bit version of SAS Enterprise Guide.  I think that the Git integration with EG (LibGit2Sharp) is specific to the bit architecture, so you have to drive this from a 64-bit process or install a 32-bit version of SAS Enterprise Guide.  Someone like @CaseySmith might be able to confirm.

View solution in original post


All Replies
Solution
‎03-21-2017 07:17 PM
Community Manager
Posts: 2,889

Re: Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)

I'm afraid that the exception is caused by using 32-bit Excel to automate a 64-bit version of SAS Enterprise Guide.  I think that the Git integration with EG (LibGit2Sharp) is specific to the bit architecture, so you have to drive this from a 64-bit process or install a 32-bit version of SAS Enterprise Guide.  Someone like @CaseySmith might be able to confirm.

SAS Super FREQ
Posts: 306

Re: Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)

Chris is correct.  The libgit2 library (git2-e0902fb.dll) (which EG accesses via LibGit2Sharp) is specific to the bit architecture.

 

If you disable EG's Program History feature (uncheck "Enable program history" in Tools->Options->Program History), you should get further, since the library is not immediately loaded in that case.  However, if you do any operations that result in EG attempting to use the library, you'll see the exception again.  (For example, I noticed simply opening a saved project causes the library to get loaded even if the Program History feature is off.)  Otherwise, I second Chris' suggested workarounds.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 550 views
  • 0 likes
  • 3 in conversation