System.NotSupportedException when trying to create an asset
I was able to create a working demo using a .NET 4.6.1 and following nuget package:
windowsazure.mediaservices v3.6.0.0
- Create a brand new MVC app.
- Add some dependency assemblies in
web.config
(if doesn't exists) https://social.msdn.microsoft.com/Forums/azure/en-US/eb05a115-36b2-47a5-b464-3220548a5de9/upgrade-to-media-services-sdk-20-error-with-microsoftpracticestransientfaulthandlingcore?forum=MediaServices - Add a post action
[HttpPost]public async Task<string> PostUpload(){ var bytes = System.Text.Encoding.UTF8.GetBytes("Test"); var data = new VideoData { Data = bytes }; CloudMediaContext _context; using (MemoryStream ms = new MemoryStream(data.Data)) { var accountName = "accountName"; var accountKey = @"primaryaccessKey"; _context = new CloudMediaContext(accountName, accountKey); var asset = await _context.Assets.CreateAsync("myjblobassets", AssetCreationOptions.None, CancellationToken.None); //... do something with asset and ms ... } return "http://my-link";}
* Note: any bytes is fine here since we are not demonstrating the upload part, we are making sure creating a Media Service Asset works.
- Add a HTML
form
and submitbutton
in the index view pointing to this post action, run it and works!!!
Note: In NAME, enter the name of the new account. A Media Services account name is all lower-case numbers or letters with no spaces, and is 3 - 24 characters in length. https://azure.microsoft.com/en-us/documentation/articles/media-services-dotnet-get-started/
I can't tell you why it's not working exactly.But i think the problem is more likely to find in the construction of your function than in the Azure API.
It should be done like this:
// Important is the return value of the function: public async Task<IAsset> CreateAssetBlobAsync(CancellationToken token) { var asset = await _context.Assets.CreateAsync("blobContainerName", AssetCreationOptions.None, CancellationToken.None); // or your 'token' return asset; }
And this async function should be called like this:
public static async Task ProcessNewBlobAsync(){ // ... var asset = await CreateAssetBlobAsync(token); // ...}
I think the problem will be your .using
Statement
Fact is the Read/Write Async
methods of MemoryStream
don't actually provide any kind of true asynchronous implementation. Which means they always will be synchronously.
(But you didn't call any of them. I fear maybe it will be a synchronous wrapper for the async method. And so it will call the API synchronous instead of asynchronous. This is only a thought.)
I recommend to avoid using-Statements with async
for preventing a deadlock.
I hope that "blobContainerName" is a mock you wrote when posting the question? Capital letters and blob containers do not mix :)