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;
}
Related
I'm currently trying to take over an advanced project coded in C#.
I'm definitely a novice concerning Visual Studio. The project was left few years ago and nobody holds details concerning the development. The only thing I know is that it was developed with the help of Visual Studio 2015 community edition. I cloned the source code with SourceTree and am now trying to generate an MSI so I can continue developing on a stable and usable version of the code.
After building the solution, I had to install few missing library including Clipper for some of the projects (version 6.4.0 by Angus Johnson). After that, most of the errors concerning Clipper disappeared but, for some reason, I still get unrecognized methods when using them with Clipper objects. I looked up and those methods should definitely exist in the library.
public static Polygons ProcessEvenOdd(this Polygons polygons)
{
var ret = new Polygons();
var clipper = new Clipper();
clipper.AddPaths(polygons, PolyType.ptSubject, true);
clipper.Execute(ClipType.ctUnion, ret);
return ret;
}
For example, here I get:
CS1061 'Clipper' does not contain a definition for 'AddPaths' and no extension method 'AddPaths' accepting a first argument of type 'Clipper' could be found (are you missing a using directive or an assembly reference?)
for (int i = 0; i < insetCount; i++)
{
// Increment by half the offset amount
currentOffset += offsetBy;
Polygons currentInset = part.IslandOutline.Offset(-currentOffset);
// make sure our polygon data is reasonable
currentInset = Clipper.CleanPolygons(currentInset, minimumDistanceToCreateNewPosition);
// check that we have actual paths
if (currentInset.Count > 0)
{
part.InsetToolPaths.Add(currentInset);
// Increment by the second half
currentOffset += offsetBy;
}
else
{
// we are done making insets as we have no area left
break;
}
if (i == 0)
{
// Reset offset amount to half the standard extrusion width
offsetBy = extrusionWidth_um / 2;
}
}
Here, I get:
CS0117 'Clipper' does not contain a definition for 'CleanPolygons'
Is there any reason those could stay unrecognizable for Visual Studio?
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
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();
}
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
When calling the Parse method in the Razor ViewEngine, compilation errors are thrown as TemplateComplilationException which contains a list of errors. Those errors refer to temporary filenames, but the files are deleted before you can access them.
static void Main(string[] args)
{
var service = TemplateServiceFactory.CreateTemplateService(Language.CSharp, true);
string result = "";
try
{
result = service.Parse("Hello #DateTime.NowXX ");
}
catch (TemplateCompilationException ex)
{
foreach (var error in ex.Errors)
if (!string.IsNullOrEmpty(error.FileName))
Console.WriteLine( File.ReadAllText( error.FileName ));
} // ^^^^ File does not exist!
Console.WriteLine( result );
Console.ReadKey();
}
(a little background)
I'm using the Razor engine "stand-alone" without MVC. When I call the Parse I want to get as much detailed information as possible to display to the user.
The current v2.1 release doesn't provide the ability to spit out the source code. There is a debugging feature in the new v3 codebase that allows the source code to be pushed out. It doesn't do this by default, because I'm trying to make the code as performant as possible (and generating the code twice (once as CodeDom, once as a string) isn't ideal). You'll need to enable the Debug flag on your configuration:
var config = new TemplateServiceConfiguration { Debug = true };
var service = new TemplateService(config);
This will enable the source code to be read when an exception is thrown.
Point of interest, through testing the Roslyn compiler infrastructure with the v3 codebase, it accepts a string source instead of CodeDom, so I'll likely make a future change to use that instead of CodeDom directly - this in turn means we have direct access to the source code without having to worry about enabling any Debug flag which will likely be deprecated.
v3 (currently v3.0.7beta) is available on Nuget (Install-Package RazorEngine). I was aiming to RTW last weekend but never got round to it.
RazorEngine's TemplateCompilationException is a class that wraps a CompilerErrorCollection that contain CompilerError objects, so the most details you could possibly get from the TemplateCompilationException CompilerError objects are their respective properties, which appears to be enough to debug with. Consider and try this example
try
{
Razor.Parse("My erroneous #DateTime.Now.foo()");
}
catch(TemplateCompilationException ex)
{
foreach(var error in ex.Errors)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Compile Error Num: \t" + error.ErrorNumber);
sb.AppendLine("Error Text:\n\t" + error.ErrorText);
Console.WriteLine(sb.ToString());
}
Console.WriteLine("Erroneous Template:\n\t" + ex.Template);
}
When I run my example this is what I get, which tells you the error(s) that was encountered and you can dump the template data to reference for your users.
Compile Error Num: CS1061
Error Text:
'System.DateTime' does not contain a definition for 'foo' and no
extension method 'foo' accepting a first argument of type
'System.DateTime' could be found (are you missing a using directive
or an assembly reference?)
Erroneous Template:
My erroneous #DateTime.Now.foo()