Azure Blob Storage Issue with downloading a file - c#

I'm working on functionality to allow users to download Azure Blob Storage items.
I am trying to get a list of blobs using:
var list = await container.GetBlobsAsync(BlobTraits.All, BlobStates.All, string.Empty).ConfigureAwait(false);
Here is the error I have though:
Error CS1061 'ConfiguredCancelableAsyncEnumerable' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'ConfiguredCancelableAsyncEnumerable' could be found (are you missing a using directive or an assembly reference?)
Is async available for C# 7.3? Or to use Async calls to obtain all the blobs in the container I need to upgrade to 8.0 C#?
If I change the code to this:
await foreach (BlobItem page in container.GetBlobsAsync(BlobTraits.None, BlobStates.None, string.Empty))
{
yield return container.GetBlobClient(page.Name);
}
Then I have this error:
Error CS8370 Feature 'async streams' is not available in C# 7.3. Please use language version 8.0 or greater.
I know GetBlobsAsync() returns AsyncPageable<> and I'm assuming it is only available in C# 8.0?

These are the 2 options I can think of :
update you're langVersion to 8 which you are saying you do not want to do
use an enumerator eg
var blobs = blobContainerClient.GetBlobsAsync()
List<BlobItem> blobList = new List<BlobItem>();
IAsyncEnumerator<BlobItem> enumerator = blobs.GetAsyncEnumerator();
try
{
while (await enumerator.MoveNextAsync())
{
blobList.Add(enumerator.Current);
}
}
finally
{
await enumerator.DisposeAsync();
}

Related

'UnityWebRequest' does not contain a definition for 'result'

When I use the code satable for the unity 2021 in the unity 2019.
The console shows that
'UnityWebRequest' does not contain a definition for 'result' and no accessible extension method 'result' accepting a first argument of type 'UnityWebRequest' could be found (are you missing a using directive or an assembly reference?)
Bugs/problem:
if (req.result == UnityWebRequest.Result.ConnectionError || req.result == UnityWebRequest.Result.ProtocolError)
I expect I can use those code on unity 2019 with other codes and works.
Simply consult the API!
result was added in version 2020.3.
Prior to that version simply follow the examples from the according version API e.g. 2019.4 API
You can e.g. simply check if there is any content in error
using (var webRequest = UnityWebRequest.Get(uri))
{
yield return webRequest.SendWebRequest();
if (!string.IsNullOrWhiteSpace(webRequest.error))
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}
Debug.Log(webRequest.downloadHandler.text);
}
or if you want to further differentiate isNetworkError (includes errors like no internet connection, host not reachable, DNS resolve error etc) and isHttpError (basically same as responseCode >= 400)
If your question is about downwards compatibility but support both versions either stick to the pre-2020.3 way or use Conditional Compilation and do e.g.
#if UNITY_2020_3_OR_NEWER
if(webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError)
#else
if(!string.IsNullOrWhiteSpace(webRequest.error))
#endif
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}

OpenTl c# IDialogs doesn't have an extension CS1061

I want to search all the telegram channels available with this :
var clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(true);
IDialogs userDialogs = await clientApi.MessagesService.GetUserDialogsAsync(100).ConfigureAwait(true);
and then get the chats, so channels like this :
var s = userDialogs.Chats.AsEnumerable; //.Chats.asEnumerable();
but I can't compile it because it's throwing this error :
Error CS1061 'IDialogs' does not contain a definition for 'Chats' and no accessible extension method 'Chats' accepting a first argument of type 'IDialogs' was found (is a using directive or assembly reference missing?).
I'm using OpenTl and when I try to debug it, the userDialogs as an attribute Chats, as well as some others.
OpenTL library

'SubscriptionClient' does not contain a definition for 'PeekBatch' and ReceiveBatch

I have a netstandard2.1 application and I am using nuget package "Microsoft.Azure.ServiceBus" Version="4.1.1".
I am creating a azure service bus SubscriptionClient and trying to use PeekBatch and ReceiveBatch, but I am getting below erros, What is missing here?
'SubscriptionClient' does not contain a definition for 'PeekBatch' and no accessible extension method 'PeekBatch' accepting a first argument of type 'SubscriptionClient' could be found
'SubscriptionClient' does not contain a definition for 'ReceiveBatch' and no accessible extension method 'PeekBatch' accepting a first argument of type 'SubscriptionClient' could be found
_subscriptionClient = new SubscriptionClient(connectionString, topicName, subscriptionName, ReceiveMode.ReceiveAndDelete);
_subscriptionClient.PrefetchCount = 16;
while (_subscriptionClient.PeekBatch(16).Any())
{
var pendingMessages = _subscriptionClient.ReceiveBatch(16, TimeSpan.FromSeconds(1))?.ToList();
if (pendingMessages != null)
{
foreach (var message in pendingMessages)
{
// do processing of the message
}
}
}
You can't use the batch methods and prefetching at the moment from .net standard or core.
Check the documentation here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements?tabs=net-standard-sdk#prefetching-and-receivebatch
Prefetching
This section only applies to the WindowsAzure.ServiceBus SDK, as the Microsoft.Azure.ServiceBus SDK does not expose batch functions.
Note that WindowsAzure here: https://www.nuget.org/packages/WindowsAzure.ServiceBus/
Please note that this package requires at least .Net Framework 4.6.2.
Is .net only and does not support net core or net standard

In C#, I am getting an error when requesting permission for speech recognition Xamarin Android

So I am using the Plugin.SpeechRecognition Nuget Package and following the exact code on line and its not working.
I have tried adding the "Plugin.Permissions" Nuget Package and that hasn't helped and i have tried googling the problem but there isn't anyone getting this issue and it seems to work fine for everyone. I have also tried removing the "await" keyword and it just says
Operator '==' cannot be applied to operands of type 'IObservable' and 'bool'
Here is my code:
private async void GetSpeechPermission()
{
var granted = await CrossSpeechRecognition.Current.RequestPermission();
if (granted == true)
{
// go!
}
}
so what should happen is there is no error what so ever and the code should run fine but the line of code
await CrossSpeechRecognition.Current.RequestPermission();
has a red underline saying
IObservable' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IObservable' could be found (are you missing a using directive or an assembly reference?)
when I am using the EXACT code provided by the creator of the plugin from here https://github.com/aritchie/speechrecognition
Any help is MUCH appreciated!!
The Solution to this was to add
using System.Reactive.Linq
in the using section of the code and instead of using a bool value as the code example for the plugin suggests, instead, in the if statement, convert the "granted" variable to a string and then check for "Available", Code:
private async void GetSpeechPermission()
{
var granted = await CrossSpeechRecognition.Current.RequestPermission();
if (granted.ToString() == "Available")
{
//GO
}
}
Hope this helps some one! :D

Could Roslyn compile await keyword?

While working with latest version of roslyn-ctp I have found that it does not support dynamic keyword while compiling and script execution, i.e. you will get an compiling error error CS8000: This language feature ('dynamic') is not yet implemented in Roslyn. Here is a short code snippet:
var engine = new ScriptEngine();
var script = #"dynamic someVariable = 0;";
// you an error CS8000: This language feature ('dynamic') is not yet implemented in Roslyn
engine.CreateSession().Execute(script);
While working with await keyword…
In contrast, while working with await keyword at compilation or script, I usually got some random compilation error like one of followings:
error CS1001: Identifier expected
error CS1003: Syntax error, ',' expected
error CS0246: The type or namespace name 'await' could not be found (are you missing a using directive or an assembly reference?)
Sample of scripting
var engine = new ScriptEngine();
new[]
{
"System", "System.Threading", "System.Threading.Tasks",
} .ToList().ForEach(#namespace => engine.ImportNamespace(#namespace));
var script = #"await Task.Run(() => System.Console.WriteLine(""Universal [async] answer is '42'""));";
engine.CreateSession().Execute(script);
Sample of compilation
// compilation sample
const string codeSnippet = #"namespace DemoNamespace
{
using System;
using System.Threading;
using System.Threading.Tasks;
public class Printer
{
public async void Answer()
{
var answer = 42;
var task = Task.Run(() => System.Console.WriteLine(string.Format(""Universal [async] answer is '{0}'"", answer)));
await task; // not working
task.Wait(); // working as expected
}
}
}";
var syntaxTree = SyntaxTree.ParseText(codeSnippet,
options: new ParseOptions(languageVersion: LanguageVersion.CSharp5));
var references = new []
{
MetadataReference.CreateAssemblyReference(typeof(Console).Assembly.FullName),
MetadataReference.CreateAssemblyReference(typeof(System.Threading.Tasks.Task).Assembly.FullName),
};
var compilation = Compilation.Create(
outputName: "Demo",
options: new CompilationOptions(OutputKind.DynamicallyLinkedLibrary),
syntaxTrees: new[] { syntaxTree },
references: references);
if(compilation.GetDiagnostics().Any())
{
compilation.GetDiagnostics().Select(diagnostic => diagnostic).Dump();
throw new Exception("Compilation failed");
}
Assembly compiledAssembly;
using (var stream = new MemoryStream())
{
EmitResult compileResult = compilation.Emit(stream);
compiledAssembly = Assembly.Load(stream.GetBuffer());
}
dynamic instance = Activator.CreateInstance(compiledAssembly.GetTypes().First());
instance.Answer();
Q: Am I missing something or it is not implemented yet?
I have tried different configuration with LanguageVersion.CSharp5 and without. Both Google and Stackoverflow searches are full of marketing hype for both roslyn and async keywords and almost useless. Microsoft "Roslyn" CTP forum also has no answer for this.
ps: as far as I know async keyword has introduced for readability both by humans and compilers while await does all magic
await support is not implemented in the current Roslyn CTP (although it is now implemented in internal builds).
The reason for the difference in error reporting is that we first built the Roslyn parser so that it could handle the entire C# 4 language, and then filled in semantics for features one at a time. Since await is a C# 5 feature, it is not even recognized by the parser, and there is no place to recognize its use and provide a good error.
Actually, the Roslyn forum does have the answer. If you look at the post Known Limitations and Unimplemented Language Features, you'll notice that it contains “Async” among the not yet implemented features in C#.
That list is about the June CTP, but since the list of changes between the June CTP and the December CTP doesn't list async, it means it's simply not implemented yet.
I think the reason for the difference in error message is that Roslyn does understand dynamic (but doesn't implement it yet). On the other hand, it doesn't understand async-await, so it gives you generic compilation errors.

Categories

Resources