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.
Related
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.
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.
We have quite a large shared project, which has 3 heads so to speak:
Windows.UWP
Windows.Desktop81
Windows.Phone81
These three each reference Portable Libraries which target both Windows 8.1 and Windows Phone 8.1.
When compiling the UWP project using the native tool chain, the portable libraries cannot access any type information so they can’t perform any reflection.
The method which is failing is a generic one, and inspects typeof(T) to do various operations depending on what type it is.
First line that throws an System.NotImplementedException is:
If (typeof(T).IsArray)
In this case, T is System.String, and if I break the debugger on the failing method and type into the immediate window of visual studio 2015, I get:
>> typeof(string).IsArray
An internal error has occurred while evaluating method System.Type.get_IsArray().
However, if I do the same in the App.OnLaunched method, that works fine. So the portable libraries cannot access any type information, even for system types like System.String.
I have tried adding platform directives for the Portable Libraries, but so far no luck.
Do you have any information regarding how to enable Portable Libraries to access type information.
I got a response back from Michal at Microsoft via email, explaining the root cause and how to get around it.
You seem to be hitting the same issue described here:
https://github.com/dotnet/corert/issues/3565, except the method in
question is Type.IsArray instead of ConstructorInfo.Invoke.
The problem is that the method Type.IsArray is declared as non-virtual
in the Portable Library contracts that your source code compiles
against, but it is virtual in the implementation assemblies used in
.NET Native. This is normally not a big problem because the C#
compiler pretty much always uses “callvirt” instruction to call the
method (even if it’s not virtual). The C# compiler shipped in Visual
Studio 2017 started doing an optimization that if a method is not
virtual and the 'this' passed to the method is known not to be null,
it uses “call” instead of “callvirt”. The result is that the code ends
up calling a method that should never have been called. The result of
the typeof() expression is known to be never null.
The good news is that we made IsArray non-virtual again as part of the
NetStandard 2.0 effort. The bad news is that .NET Native with support
for NetStandard 2.0 hasn’t shipped yet.
You’ll need a workaround. The easiest I can think of is to add an
extension method and use that instead:
static class NetNativeWorkarounds
{
public static bool IsArray(this Type type) => type.IsArray;
}
Using the extension method avoids the C# compiler optimization because
this condition is not met (the compiler doesn’t know what type you’ll
pass to the extension method and has to do a callvirt to the
Type.IsArray method).
I have inherited a WCF RIA, Silverlight 4 application that has been dormant for a few years. It is assumed that the code is stable. To get it working I need to install dependencies which were not documented, as far as I can tell.
After installing dependencies based on what information I could gather I am left with the following error.
Operation named 'namereplaced' does not conform to the required
signature. Parameter types must be an entity type or one of the
predefined serializable types
I already tried uninstalling Ria Services as recommended here.
WCF Ria Operation does not conform to the required signature
but this leads to more errors.
I've also tried hunting down a specific version of the Ria Services Toolkit as suggest here, but no luck
https://social.msdn.microsoft.com/Forums/silverlight/en-US/86f40859-18e8-4ce6-8d8a-a864fbe4e3ac/error-operation-named-createuser-does-not-conform-to-the-required-signature-parameter-types?forum=silverlightwcf
Additionally, I tried setting up a drop retrieved from the client's FTP in IIS and saw the following in the machine Event Log
: The service
'/AppName/Services/SomeManager-Web-Services-ImportService.svc' cannot
be activated due to an exception during compilation. The exception
message is: Operation named 'namereplaced' does not conform to the
required signature. Parameter types must be an entity or complex type,
a collection of complex types, or one of the predefined serializable
types.. ---> System.InvalidOperationException: Operation named
'namereplaced' does not conform to the required signature. Parameter
types must be an entity or complex type, a collection of complex
types, or one of the predefined serializable types.
However, using an old installer that the IT team found in the old developers files, I was able to set up an instance of the website which does not generate these errors, but is incompatible with the latest version of the database. I haven't found the source for the setup project in source control.
The method in question is defined as follows
[Invoke(HasSideEffects=true)]
public void NameReplaced(IEnumerable<ImportRecord> recs)
{
foreach (var item in recs)
{
UpdateImportRecord(item);
}
}
I'd ideally like to resolve this without trying to change the code as an investigation needs to be done on an error in the clients environment, then further updates are required.
EDIT:
Included suggestion from Mark W,
public IQueryable<ImportRecord> GetImportRecords()
{
return null;
}
but the same build error is reported.
Since this project is being resurrected for some purpose, I recommend that you use the latest Visual Studio and move it to Silverlight 5. The thought is why deal with old technology which will frankly hamper the process.
Comment out the things that don't work to until you have a running (not operational though) baseline to start from. Then bring back in the things which are causing problems.
I say this from having worked extensively in both S4 & S5 and frankly (to the code) not much changed; in doing this process, yes the upgrade will have problems but they are not insurmountable. Plus the installs smarts got better for S5 and later versions of Visual Studio.
We run RIA Services on a server that does not have it installed. What we did was publish the web site with Copy Local = true on:
System.ServiceModel.DomainServices.EntityFramework
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Hosting.OData
System.ServiceModel.DomainServices.Server
If that is not it - Due to the magic of domain services, the service needs to auto-generate the class type. Only types that are returned from the service are generated. If the domain service does not have a method to return an Iqueryable or Ienumerable of type ImportRecord, you can create a method that returns null - that will be enough for the code to generate.
Those are my 2 first thoughts.
EDIT: This looks like what I'm talking about :previously asked question
In my PCL core project (WP8, Android, iOS, Xamarin, MvvmCross) I use custom attributes. The Type.GetCustomAttributes() extension method lets me examine the attributes used.
Using PCL Profile104 this works well. But because I want to use async/await, I'll need to use PCL Profile78 (and .NET 4.5)
Problem: Seems the GetCustomAttributes() and the Attributes property are not available in Profile78. Why??
Note:
I am looking into the workaround by creating a PCL Profile 104 class library and wrapping the GetCustomAttributes() and then referencing this library from my PCL Profile78 library. However it seems extensionmethods are not supported...
Example Code:
public Pcl78Class()
{
Type t = this.GetType();
var attributes = t.Attributes;
var customAttributes = t.GetCustomAttributes(true);
// another weird thing: Why is VS CodeCompletion telling me it knows CustomAttributeExtensions class and methods?
//System.Reflection.CustomAttributeExtensions.GetCustomAttributes(t);
}
Problem: Seems the GetCustomAttributes() and the Attributes property are not available in Profile78. Why??
Profile78 includes support for Windows Store 8 (as noted on my blog), and Windows Store has a more efficient implementation of Type-based reflection. Essentially, you just have to call Type.GetTypeInfo to get a TypeInfo, and from there it should be pretty straightforward.