GoogleCloudPlatform / google-cloud-powershell

PowerShell cmdlets for the Google Cloud Platform
http://googlecloudplatform.github.io/google-cloud-powershell/
Apache License 2.0
135 stars 61 forks source link

Start-BqJob type initializer exception on PowerShell Core #578

Closed adarobin closed 6 years ago

adarobin commented 6 years ago

I'm seeing the following error trying to use Start-BqJob on PowerShell Core:

PS /Users/adarobin> $project = "redacted"
PS /Users/adarobin> $datasetName = "redacted_billing_export"
PS /Users/adarobin> $tableName = "gcp_billing_export_v1_redacted"
PS /Users/adarobin> $destTable = Get-BqTable -Project $project -DatasetId "monthly_export" -Table "2017_11"
PS /Users/adarobin> Start-BqJob -Query "SELECT * FROM ``$($project).$($datasetName).$($tableName)`` WHERE FORMAT_TIMESTAMP('%Y-%m-%d', usage_start_time) LIKE '2017-11-%'" -Destination $destTable
Start-BqJob : The type initializer for 'Google.Cloud.BigQuery.V2.BigQueryClientImpl' threw an exception.
At line:1 char:1
+ Start-BqJob -Query "SELECT * FROM ``$($project).$($datasetName).$($ta ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Start-BqJob], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Google.PowerShell.BigQuery.StartBqJob

# If I run this Resolve-Error function I found on stackoverflow, it appears that this is failing because of a missing DLL named Microsoft.Extensions.PlatformAbstractions.

PS /Users/adarobin> Resolve-Error                                                                       

PSMessageDetails      : 
Exception             : System.TypeInitializationException: The type initializer for 
                        'Google.Cloud.BigQuery.V2.BigQueryClientImpl' threw an exception. ---> 
                        System.IO.FileNotFoundException: Could not load file or assembly 
                        'Microsoft.Extensions.PlatformAbstractions, Version=1.1.0.0, Culture=neutral, 
                        PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

                           at Google.Api.Gax.VersionHeaderBuilder.AppendDotNetEnvironment()
                           at Google.Api.Gax.Rest.UserAgentHelper.CreateRequestModifier(Type type)
                           at Google.Cloud.BigQuery.V2.BigQueryClientImpl..cctor()
                           --- End of inner exception stack trace ---
                           at Google.Cloud.BigQuery.V2.BigQueryClientImpl.get_ApplicationName()
                           at Google.Cloud.BigQuery.V2.BigQueryClient.CreateImpl(String projectId, 
                        GoogleCredential scopedCredentials)
                           at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
                           at System.Lazy`1.ExecutionAndPublication(LazyHelper 
                        executionAndPublication, Boolean useDefaultConstructor)
                           at System.Lazy`1.CreateValue()
                           at Google.PowerShell.BigQuery.StartBqJob.DoQuery()
                           at Google.PowerShell.BigQuery.StartBqJob.ProcessRecord()
                           at System.Management.Automation.Cmdlet.DoProcessRecord()
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [Start-BqJob], TypeInitializationException
FullyQualifiedErrorId : System.TypeInitializationException,Google.PowerShell.BigQuery.StartBqJob
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

MyCommand             : Start-BqJob
BoundParameters       : {}
UnboundArguments      : {}
ScriptLineNumber      : 1
OffsetInLine          : 1
HistoryId             : 11
ScriptName            : 
Line                  : Start-BqJob -Query "SELECT * FROM 
                        ``$($project).$($datasetName).$($tableName)`` WHERE 
                        FORMAT_TIMESTAMP('%Y-%m-%d', usage_start_time) LIKE '2017-11-%'" -Destination 
                        $destTable
PositionMessage       : At line:1 char:1
                        + Start-BqJob -Query "SELECT * FROM ``$($project).$($datasetName).$($ta ...
                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot          : 
PSCommandPath         : 
InvocationName        : Start-BqJob
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition : 

00000000000000000000000000000000000000000000000000000000000000000000000000000000

TypeName       : Google.Cloud.BigQuery.V2.BigQueryClientImpl
Message        : The type initializer for 'Google.Cloud.BigQuery.V2.BigQueryClientImpl' threw an 
                 exception.
Data           : {}
InnerException : System.IO.FileNotFoundException: Could not load file or assembly 
                 'Microsoft.Extensions.PlatformAbstractions, Version=1.1.0.0, Culture=neutral, 
                 PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

                 File name: 'Microsoft.Extensions.PlatformAbstractions, Version=1.1.0.0, 
                 Culture=neutral, PublicKeyToken=adb9793829ddae60'
                    at Google.Api.Gax.VersionHeaderBuilder.AppendDotNetEnvironment()
                    at Google.Api.Gax.Rest.UserAgentHelper.CreateRequestModifier(Type type)
                    at Google.Cloud.BigQuery.V2.BigQueryClientImpl..cctor()

TargetSite     : System.String get_ApplicationName()
StackTrace     :    at Google.Cloud.BigQuery.V2.BigQueryClientImpl.get_ApplicationName()
                    at Google.Cloud.BigQuery.V2.BigQueryClient.CreateImpl(String projectId, 
                 GoogleCredential scopedCredentials)
                    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
                    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, 
                 Boolean useDefaultConstructor)
                    at System.Lazy`1.CreateValue()
                    at Google.PowerShell.BigQuery.StartBqJob.DoQuery()
                    at Google.PowerShell.BigQuery.StartBqJob.ProcessRecord()
                    at System.Management.Automation.Cmdlet.DoProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()
HelpLink       : 
Source         : Google.Cloud.BigQuery.V2
HResult        : -2146233036

11111111111111111111111111111111111111111111111111111111111111111111111111111111

Message        : Could not load file or assembly 'Microsoft.Extensions.PlatformAbstractions, 
                 Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot 
                 find the file specified.

FileName       : Microsoft.Extensions.PlatformAbstractions, Version=1.1.0.0, Culture=neutral, 
                 PublicKeyToken=adb9793829ddae60
FusionLog      : 
Data           : {}
InnerException : 
TargetSite     : Google.Api.Gax.VersionHeaderBuilder AppendDotNetEnvironment()
StackTrace     :    at Google.Api.Gax.VersionHeaderBuilder.AppendDotNetEnvironment()
                    at Google.Api.Gax.Rest.UserAgentHelper.CreateRequestModifier(Type type)
                    at Google.Cloud.BigQuery.V2.BigQueryClientImpl..cctor()
HelpLink       : 
Source         : Google.Api.Gax
HResult        : -2147024894
quoctruong commented 6 years ago

@adarobin Thanks for reporting the issue. Do you mind telling us if this is happen on PowerShell Core on Windows or Linux?

adarobin commented 6 years ago

@quoctruong sorry I should have specified I am on macOS 10.12.6.

PS /Users/adarobin> $PSVersionTable                                             

Name                           Value                                           
----                           -----                                           
PSVersion                      6.0.0-rc                                        
PSEdition                      Core                                            
GitCommitId                    v6.0.0-rc                                       
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: M...
Platform                       Unix                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1                                         
WSManStackVersion              3.0                                             
quoctruong commented 6 years ago

@adarobin Thank you. Were you able to use other cmdlets as well?

adarobin commented 6 years ago

@quoctruong other cmdlets seem to be working fine. For example:

PS /Users/adarobin> $project = "redacted"
PS /Users/adarobin> $datasetName = "redacted_billing_export"
PS /Users/adarobin> $tableName = "gcp_billing_export_v1_redacted"
PS /Users/adarobin> Get-BqTable -Project $project -DatasetId $datasetName -Table $tableName                                                                     

CreationTime              : 1507847568774
Description               : 
EncryptionConfiguration   : 
ETag                      : "ob-86LeXR440kDFLbYyIXtsn6z4/MTUxMDI3MjU0NDc0Ng"
ExpirationTime            : 
ExternalDataConfiguration : 
FriendlyName              : 
Id                        : redactedr:redacted_billing_export.gcp_billing_ex
                            port_v1_redacted
Kind                      : bigquery#table
Labels                    : 
LastModifiedTime          : 1513021634008
Location                  : US
NumBytes                  : 11875404
NumLongTermBytes          : 0
NumRows                   : 53422
Schema                    : Google.Apis.Bigquery.v2.Data.TableSchema
SelfLink                  : https://www.googleapis.com/bigquery/v2/projects/redacted/datasets/redacted_billing_export/tables/gcp_billing_export_v1_redacted
StreamingBuffer           : 
TableReference            : Google.Apis.Bigquery.v2.Data.TableReference
TimePartitioning          : Google.Apis.Bigquery.v2.Data.TimePartitioning
Type                      : TABLE
View                      : 
quoctruong commented 6 years ago

@adarobin Thank you. I'll do further investigation on this.

quoctruong commented 6 years ago

@adarobin I've fixed this issue and published a new version of the module 1.0.1.2. Please try it out!

adarobin commented 6 years ago

@quoctruong It is working now, thanks!