Reputation: 15391
I must be missing something obvious here, but I find myself unable to do an upcast which I thought was legal. I am trying to upload data to Blob storage in Azure, and would like to use the method CloudBlob.UploadText(string). However, when I access my blob, I get a CloudBlockBlob instance, which as far as I can tell inherits from CloudBlob, and the method UploadText is not accessible, so I tried let blob = targetBlob :> CloudBlob
- which fails miserably, with the message
SmallScript.fsx(28,12): error FS0193: Type constraint mismatch. The type
CloudBlockBlob
is not compatible with type
CloudBlob
The type 'CloudBlockBlob' is not compatible with the type 'CloudBlob'
I can upload data just fine using UploadFromStream, but UploadText would be pretty convenient for my purposes. Can anyone help me see what I am missing?
For the record, in case this helps, here is the code that works:
let credentials = StorageCredentials(accountName, accountKey)
let storageAccount = CloudStorageAccount(credentials, true)
let client = storageAccount.CreateCloudBlobClient()
let containerName = "numerics"
let container = client.GetContainerReference(containerName)
container.CreateIfNotExists() |> ignore
let targetBlobName = "MiniSparseMatrix.csv"
let targetBlob = container.GetBlockBlobReference(targetBlobName)
let fileLocation = @"C:\Users\Mathias\Desktop\TestMatrix.txt"
let stream = System.IO.File.OpenRead(fileLocation)
targetBlob.UploadFromStream(stream)
stream.Close()
Upvotes: 3
Views: 1307
Reputation: 42373
Are you possibly referencing multiple versions of libraries? My guess would be that the CloudBlockBlob
you're getting is not from the same assembly (version) as the one your code references that has the CloudBlob
type.
If you can comment out the code that doesn't compile, and attach the debugger, you should be able to confirm this by examining the type in the QuickWatch window and looking at its type (look at .GetType().Assembly
and compare it to typeof(CloudBlob).Assembly
).
Upvotes: 0