1

I'm trying to call Microsoft.AnalysisServices.Tabular.JsonScripter in my Powershell script to automatically generate CreateOrReplace database scripts for SSAS Tabular. But I keep getting the following error.

Exception calling "ScriptCreateOrReplace" with "1" argument(s): "Could not load file or assembly
'Microsoft.AnalysisServices.AppLocal.Tabular.Json, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
or one of its dependencies. The system cannot find the file specified."
At C:\Desktop\json.ps1:10 char:1
+ [Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrRepl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

Here is the code Im testing:

Import-Module SqlServer
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Core");
$tab = "server";
$dbId = "database";
$as = New-Object Microsoft.AnalysisServices.Tabular.Server;
$as.Connect($tab);
$db = $as.Databases[$dbId];

[Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrReplace($db);

the assemblies load the following:

GAC    Version        Location
---    -------        --------
True   v4.0.30319     C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.AnalysisServices.Tabular\v4.0_14.0.0.0__8...
True   v4.0.30319     C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.AnalysisServices.Core\v4.0_14.0.0.0__8984...

so the assemblies should be recognized, but yet its complaining about them. What am i supposed to do in this case?

Cataster
  • 3,081
  • 5
  • 32
  • 79

1 Answers1

2

I think the issue is that the SqlServer module appears to be loading it's own "AppLocal" version of the AMO assemblies. If you remove the first line from your script it should work. You can also simplify it as follows to just load the main AMO assembly ( this will load any other dependencies as required) and just using Microsoft.AnalysisServices.Server to connect instead of the tabular specific class.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices");

$tab = "localhost\tab17";

$dbId = "testing";

$as = New-Object Microsoft.AnalysisServices.Server;

$as.Connect($tab);

$db = $as.Databases[$dbId];

[Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrReplace($db);
Cataster
  • 3,081
  • 5
  • 32
  • 79
monaa
  • 46
  • 4