0
votes

So I have this Powershell script to install MySql dll in gac.

[System.Reflection.Assembly]::Load("System.EnterpriseServices,Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")    

$publish = New-Object System.EnterpriseServices.Internal.Publish 

$publish.GacInstall("C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.9\Assemblies\v4.5\MySql.Data.Entity.EF6.dll")

This script works fine on Windows Server 2012 R2 but throws exception on windows server 2008 r2.

Exception calling "Load" with "1" argument(s): "Could not load file or assembly 'System.EnterpriseServices, Version=4.0 .0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file spe cified." At C:\Users\Administrator\Desktop\MyScript.ps1:2 char:35 + [System.Reflection.Assembly]::Load <<<< ("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken =b03f5f7f11d50a3a") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

1) Powershell runned as administrator

2) System.EnterpriseServices exist in the system with 4.0.0 version (Location: C:\Windows\Microsoft.NET\assembly\GAC_64\System.EnterpriseServices)

3) GacUtil is not an option since sdk won't be available on production environment.

Is there any limitation of how we install the Gac on windows server 2008 r2?

Why does the script working in windows server 2012 r2 doesn't work on window server 2008 r2?

Am i missing any setting on Server to get this working?

2
can you drop the version part of the assembly name?Daniel A. White
tried like this "System.EnterpriseServices, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", same errorGaurav Singh
just the System.EnterpriseServicesDaniel A. White
Same error: Exception calling "Load" with "1" argument(s): "Could not load file or assembly 'System.EnterpriseServices' or one of i ts dependencies. The system cannot find the file specified." At C:\Users\Administrator\Desktop\MySqlEf6Gac.ps1:2 char:35 + [System.Reflection.Assembly]::Load <<<< ("System.EnterpriseServices") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodExceptionGaurav Singh
@DanielA.White Though if i use assembly version 2.0.0 as [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") , script run successfully but nothing gets installed in GAC. In event viewer i get warning: Installation in the global assembly cache failed: C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.9\Assemblies\v4.5\MySql.Data.Entity.EF6.dll : Source : COM+ SOAP ServicesGaurav Singh

2 Answers

0
votes

I Found the answer:

Powershell on windows server 2008 r2 uses CLR verion 2.0 and System.Enterpriseservice dll is created with CLR version 4.0. Powershell version on windows server 2012 r2 is 4.0 which is why this script was running fine on windows server 2012 r2. Version can be checked using : $psversiontable

Thus, powershell is unable to load this dll.

Now how to get around this error: change the powershell version to use CLR 4.0

How: https://community.dynamics.com/ax/b/daxbeginners/archive/2013/12/08/this-assembly-is-built-by-a-runtime-newer-than-the-currently-loaded-runtime-and-cannot-be-loaded

Script to Run to change PS CLR version:

Open Notepad and paste the following code:

$config_text = @"
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319"/>
    <supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
"@

$config_text| Out-File $pshome\powershell.exe.config
$config_text| Out-File $pshome\powershell_ise.exe.config

Save it and then rename the file extension to .PS1. Run as Admin.

Stumbled across this article which explain everything about error and how to change the Powershell version.

Hope this helps someone :)

-1
votes

"Please reinstall your .NET Framework (3.5 or above), restart your computer and try again." https://community.powerbi.com/t5/Desktop/Unnable-to-connect-to-SQL-Server-2012/m-p/177331 "Installed the framework 4.5 and boot the system and now it works."