dojo.tech C# examples not compiling - c#

I'm trying to get the dojo.tech C# examples to work and they are not compiling under visual studio 2022.
Tried googling some lines of code to see if I could figure which version of C#/.net but as of yet haven't figured it out.
Here is the code
// read request body as a byte stream
using var streamReader = new StreamReader(HttpContext.Request.Body);
var body = await streamReader.ReadToEndAsync();
// Get signature header value
if (HttpContext.Request.Headers.TryGetValue(WebhookPayloadUtils.SignatureHeaderName, out var signatureHeader))
{
// use Dojo.Net SDK to deserialize and validate webhook payload
var payload = WebhookPayloadUtils.ReadPayload(body, _webhookSecret, signatureHeader);
// TODO: update your database or do some action based on successful payment
}
The example comes from
here https://github.com/dojo-engineering/dojo-samples/blob/main/webhooks/cs/verify-webhooks.cs
Dojo.techs webpage is here
https://docs.dojo.tech/docs/development-resources/webhooks
Compiler errors include:
CS1617 Invalid option '8.0' for /langversion; must be ISO-1, ISO-2,
Default or an integer in range 1 to 6.
CS8370 Feature 'using declarations' is not available in C# 7.3. Please
use language version 8.0 or greater.
CS0120 An object reference is required for the non-static field,
method, or property 'HttpContext.Request'
CS4033 The 'await' operator can only be used within an async method.
Consider marking this method with the 'async' modifier and changing
its return type to 'Task'.
CS0120 An object reference is required for the non-static field,
method, or property 'HttpContext.Request'
I'm using visual studio 2022 with the latest updates (Version 17.4.4). I've tried pasting into a webform project and .net core blazor. I do NuGet to get the Dojo.tech package that part seems to work ok. I can reduce compiler errors but I struggling to find the exact configuration they are using.

I finally managed to contact the developers. The code is abbreviated (not sure the reasoning). The code needs to be inserted into the controller section of MVC project.

Related

How to use Kotlin.Result in a Xamarin.Android bindings project?

I am trying to bind a Kotlin package which is using the Kotlin.Result type. If I look at the .aar with the Java-Decompiler tool I see that some methods have return types like Result<String> or Result<SomeClass>.
How can I get the actual result from the Result, because the Xamarin binding (Xamarin.Kotlin.StdLib 1.7.20.1) does't have a generic implementation and is missing the methods described on the Kotlin website (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/).
Is there a way to get the generic type of the Kotlin.Result class in Xamarin.Android.
I have looked at older and newer versions of the nuget package Xamarin.Kotlin.StdLib. In an older version the KotlinKt class has had a method ThrowIfFailure (or something like this), but this is missing in the newer releases.
For now I only can resolve the Result<string> type by converting the Result to a string, using the ToString extension, and check if it starts with failed or success. If it is failed then I throw an exception else I remove "succes(" and ")" from the result so I get the string value. This doesn't work if the type is class with multiple properties.

.net core COM with Excel range

I have an issue where I am unable to access the Name object of a range. So, I am calling Excel.Application.get_Range() and passing in a name. It returns a non-null object and I can access methods. However, Range.Name returns a System.__ComObject(). If I try to access Range.Name.Name I get an exception similar to the following
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for "Name"
Also, this project is one that I migrated from .net Framework to .net Core. The exact same code works in Framework. I have tried various methods of trying to determine what the underlying type is (because it does not appear to be a Name object). ITypeInfo returns that the typename is Name so it does appear to be a name object.
I'm at a loss as to why I'm unable to access Name.Name in .net core. When I check the .net Core Excel sample they never access a name object.
Also, I am able to access other COM objects like ListObject just fine.
I figured out what the issue is. For anyone else running into this with .net Core, the problem is that .net core appears to not support dynamic types through COM automatically. This is discussed in the following github issue Github issue about dynamic not working. Where it talks about why this doesn't work.
Basically, for my specific case I needed to cast the type manually and then it worked. This also impacts use of IEnumerable COM types needing to be cast directly to IEnumerable before iterating through them.
Assuming you have the following using statement.
using Excel = Microsoft.Office.Interop.Excel;
I had to turn the following:
return range.Name.Name;
into
return ((Excel.Name)range.Name).Name;
As an aside, I also noticed that if you copy/paste the cast above into the debug watch window it does not display properly and instead shows an exception about an invalid cast.

Audit.WebAPI configuration

I am using version 7.0.6 of Audit.NET.
I added the following line to my WEB API registration method
config.Filters.Add(new Audit.WebApi.AuditApiAttribute());
When i run the application it gives the following runtime error
self referencing loop detected with type Appinstance.Path 'Action.ActionParameters.request.Properties.MS_HttpContext.ApplicationInstance.Context'.
I am using latest version of Newtonsoft.JSON from Nuget.
Can you provide the stack trace?
That error means Newtonsoft.Json was unable to serialize an object that has a reference loop, but the json conversion used by default on Audit.NET already handles this, by ignoring the reference loops with ReferenceLoopHandling setting set to Ignore.
https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.NET/AuditEvent.cs#L73
Are you using a custom data provider to save the events?
If so, please be sure to use the provided AuditEvent ToJson method, or any other method that handles self references.

RallyApi - cannot create defect - get error about JsonObject not containing a definition for 'CreateResult'

I am using an older version of .NET RallyApi (version 1.31) from a C# .NET 4 project (full .NET framework).
Using this code:
var x = this.RestApi.Create("defect", defectData.GetJsonObject());
CreateResult res = x as CreateResult;
when the Create() call executes, I get a RuntimeBinderException that says "'Rally.RestApi.DynamicJsonObject' does not contain a definition for 'CreateResult'"
The DynamicJsonObject returned by GetJsonObject() contains 14 fields (stuff like Project, Owner, Name, Description, Notes, etc.)
I cannot figure out what this error is telling me here... i.e. what I am doing wrong. This code has worked in the past - now I am on a new Windows domain, I am wondering if it's some sort of security issue hitting the web service, but I CAN do queries to get things like a list of Rally projects... and my Rally user has Subscription Admin privileges...
I updated to the latest rally .NET API code (I got the source and compiled it myself) and now it works - even with the 1.31 version that I am specifying. Not sure why that worked, but it does...

Can execute Code Dynamically in monotouch?

In C# .net we can run code dynamically by using System.Codedom.Provider. Like the same is there any possibility to execute the code dynamically in Monotouch (iPhone/iPad).
Thanks in advance,
Not possible. First because the limitation in how Xamarin.iOS actually works (it doesn't run like a regular .NET apps, but instead compiled to a plain iOS app) and because the security model in Apple Appstore. After all, you can't declare an app to be safe or regulation conforming if the behavior could change anytime.
Since Xamarin.iOS version 7.2 there is some basic support for C#'s dynamic feature. From the release notes:
Experimental:
C# dynamic support. We made it possible to use C# dynamic with Xamarin.iOS but the feature is very complex and we need early adopters let us know what dynamic code they run on other platforms or would like to run on Xamarin.iOS.
I've successfully compiled and executed dynamic access of anonymous types:
dynamic d = new { name = "x" };
tmp = d.name;
Currently you need to add a Microsoft.CSharp.dll as a dependency -- otherwise you'll get an exception similar to this:
Error CS0518: The predefined type `Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported (CS0518) (DynamicSupportOniOS)
Error CS1969: Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference (CS1969) (DynamicSupportOniOS)
Unfortunately neither ExpandoObject nor Json.Net's JObject work right now:
dynamic x = new ExpandoObject();
x.NewProp = "demo"; // this still works
Console.WriteLine(x.NewProp); // fails with Xamarin.iOS 7.2
dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");
Console.WriteLine(d.number); // fails with Xamarin.iOS 7.2
I've created two bug reports for this: https://bugzilla.xamarin.com/show_bug.cgi?id=20081 and https://bugzilla.xamarin.com/show_bug.cgi?id=20082.

Categories