I am starting to play with rx extension for .NET and downloaded some sources.
Basic examples works fine, however there is a function causing an error apparently because an extension method is not declared (should be imported with some directive)
The line of code causing the error is the 2nd one (list.Run) in the commented source (I commented to be able to compile):
/*
protected static void WriteListToConsole<T>(IEnumerable<T> list, string name) {
list.Run(
value => Console.WriteLine("{0} : {1}", name, value),
() => Console.WriteLine("{0} Completed", name));
}
*/
it looks like Rx defines somewhere an ext. method Run to IEnumerable but I am not importing it.
I installed Rx v2.0.3 SDK.msi , added references in my project to all System.Reactive.* I found and used:
using System;
using System.Reactive.Subjects;
using System.Reactive.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
I also tried use the Nuget rx.main and ix.main packages in my project but the error is always there.
Searching on google IEnumerable + Run gives me no info.
Any help appreciated.
Thanks
Hi I think that is a very old sample you are looking at.
This is now replaced with the extension method ForEach which can be found in the System.Linq namespace in the System.Interactive dll (IX-Main nuget I think).
You will also note that the OnCompleted function parameter is gone, cause well it was a silly idea. The new code should look like:
protected static void WriteListToConsole<T>(IEnumerable<T> list, string name)
{
list.ForEach(value => Console.WriteLine("{0} : {1}", name, value));
Console.WriteLine("{0} Completed", name);
}
Related
I added the google play core package as instructed in the repo, and added the code according to the documentation here
I receive the following error: CS0246: The type or namespace name 'PlayAsyncOperation<,>' could not be found (are you missing a using directive or an assembly reference?)
This error shows at _reviewManager.RequestReviewFlow(); and _reviewManager.LaunchReviewFlow(_playReviewInfo)
Any idea what could be the issue?
My full code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Google.Play.Review;
public class ReviewCodes : MonoBehaviour
{
private ReviewManager _reviewManager;
private PlayReviewInfo _playReviewInfo;
// Start is called before the first frame update
void Start()
{
StartCoroutine(RequestReviews());
}
// Update is called once per frame
void Update()
{
}
IEnumerator RequestReviews()
{
// Create instance of ReviewManager
_reviewManager = new ReviewManager();
var requestFlowOperation = _reviewManager.RequestReviewFlow();
yield return requestFlowOperation;
if (requestFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
_playReviewInfo = requestFlowOperation.GetResult();
var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);
yield return launchFlowOperation;
_playReviewInfo = null; // Reset the object
if (launchFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
}
}
"are you missing a using directive or an assembly reference?"
These are following situation which causes a compiler error:
Check if the name of the type or namespace is correct, as most of the time you can get this error when the compiler cannot find that namespace.
Check if you have added the reference to the assembly that contains the namespace. Ex: Your code can be in "using XYZ;"
but if your project does not reference assembly then you can get a CS0246 error.
Try: using Google.Play.Common;
the order might be your problem. You also not only have to import the Google Core Package. You also have to import the Google Review Plugin. The core plugin overrides assemblies and files which then can't be used by the review assembly.
Step-by-Step solution:
Import google-play-plugins-1.7.0.unitypackage
Import com.google.play.review-1.7.0.unitypackage
Make sure to restart your IDE or reload the code in your IDE after this steps.
In older versions in unity there was an option to download this packages with the help of the unity package manager. Now you have to use the official github repository from Google. See Downloading the plugins or just use the official provided .unitypackages from Google
Using Xamarin Forms Visual Studio 2019.
I need to get the DPI of the device.
This post has a solution:
How to get DPI device to PCL in Xamarin. Forms?
Implementing the solution gave problems:
When applying the answer above I get this error message:
The type or namespace name 'DependencyAttribute' could not be found
(are you missing a using directive or an assembly reference?)
In your android implementation, add a new class:
[assembly: Dependency(typeof(DisplayInfo))]
namespace .....
--I solved this compiler problem by replacing with:
using Xamarin.Essentials;
[assembly: Xamarin.Forms.Dependency(typeof(DisplayInfo))]
However when I compile and run the code, it falls over when I try consume this in the Xamarin Core Code:
int dpi = DependencyService.Get<IDisplayInfo>().GetDisplayDpi();
I get this runtime error on the above line:
System.NullReferenceException: Object reference not set to an instance
of an object
Any ideas? I would have added this question as a comment on the original, but as a new user do not have the points to do this... If someone could drop a comment on the original question's solution pointing it to this URL that would be helpful too.
So the answer to my own question:
The solution original offered said do this:
In your android implementation, add a new class:
[assembly: Dependency(typeof(DisplayInfo))]
namespace YourAppNamespace.Droid
{
public class DisplayInfo : IDisplayInfo
{
public int GetDisplayWidth()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.WidthPixels;
}
public int GetDisplayHeight()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.HeightPixels;
}
public int GetDisplayDpi()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.DensityDpi;
}
}
}
The problem I did not see anywhere in the Android code that initialised this class, and I was unsure how best to do this really.
So I followed guidance for implementing the interface directly in the Android MainActivity.cs file, and this worked.. The video I watched to help me on that is here:
https://www.youtube.com/watch?v=lgcnYDb6cRQ&t=19s
I got a tiny script that creates a text file in Resources folder before building that needs to be included in the build. So I wrote this script using Unity's IPreprocessBuildWithReport:
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using System.IO;
class MyCustomBuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
{
File.WriteAllText(
Application.dataPath + "/Resources/version.txt",
string.Format("{0}", PlayerSettings.Android.bundleVersionCode));
AssetDatabase.Refresh();
}
}
Note the AssetDatabase.Refresh(); statement at the end. It makes sure Unity becomes aware of the change and includes the updated file in the build. Now, whenever time I change the bundleVersionCode and press build, Unity updates the file as expected but the build fails with this pretty generic error:
However, if I try to build the second time with the same bundleVersionCode than no file changes occur and the build succeeds.
So I guess the AssetDatabase.Refresh() doesn't really work in OnPreprocessBuild(), or am I doing something obviously stupid again? Can anyone suggest a workaround?
EDIT:
Please ignore the first two errors, just Unity doesn't like me when I'm excluding files from build by the ~ postfix.
I'm doing some experiments with Phalcon Zephir to see how well it can convert some of my libraries to PHP extensions.
I have two PHP classes, each already defined in its own file: the Zephir notes are quite clear that this must be the case.
trienode.zep
namespace tries;
class trienode
{
public children;
public valueNode = false;
public value = null;
public function __construct()
{
let this->children = [];
}
}
and
trie.zep
namespace tries;
class trie {
private trie;
public function __construct() {
let this->trie = new trienode();
}
}
But whenever I try to compile the classes using zephir compile, I get
Warning: Class "trienode" does not exist at compile time in /home/vagrant/ext/tries/tries/trie.zep on 8 [nonexistent-class]
let this->trie = new trienode();
---------------------------------------^
(and if I continue through the build process, and install the resultant .so file, it errors when I try to use it from within a PHP script)
<?php
namespace tries;
$test = new trie;
giving
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/tries.so' - /usr/lib/php5/20121212/tries.so: undefined symbol: zephir_tries_trie_init in Unknown on line 0
PHP Fatal error: Class 'tries\trie' not found in /home/vagrant/triesTest.php on line 5
I've looked through the Zephir documentation, and various blog posts, but can't find any examples of building an extension that comprises more than a single class file.
Has anybody succeeded in building an extension using Zephir that does comprise more than a single class? And if so, what settings or configuration options (or additional steps) does it require to build a working so?
It looks like the namespace has to be included in the call.
let this->trie = new tries\trienode();
// ^^^^^^
I didn't see this explicitly mentioned in the documentation, but is hinted at (pardon the pun) in the Return Type Hints section, which uses the namespace in the hints.
Changing your example class to that shown above allows the extension to compile as desired.
I've created an app using MVVMCross, the IOS and Android versions are working but when I tried to "port" to WP7 and I ran into the following problem:
throw methodAccessException.MvxWrap("Problem accessing object - most likely this is caused by an anonymous object being generated as Internal - please see http://stackoverflow.com/questions/8273399/anonymous-types-and-get-accessors-on-wp7-1");
As mentioned in the answer to my other question about this (on Android) you have to set an InternalsVisibleTo attribute in the AssemblyInfo.cs for WP7. So I did:
[assembly: InternalsVisibleTo("Cirrious.MvvmCross.WindowsPhone")]
But this doesn't make any difference. I use the following code to send two variables form my BeckhoffViewModel to my BeckhoffSensorViewModel.
BeckhoffViewModel:
public IMvxCommand BeckhoffSensor1
{
get
{
return new MvxRelayCommand(kvpSens1);
}
}
private void kvpSens1()
{
RequestNavigate<BeckhoffSensorViewModel>(new { VarType = "short", Variable = ".countertest" });
}
BeckhoffSensorViewModel:
public BeckhoffSensorViewModel(string VarType, string Variable)
{
_vartype = VarType;
_variable = Variable;
}
Anything I'm overlooking? I also looked at the other stackoverflow topic mentioned in the exception but couldn't really understand it.
The anonymous class will most definitely be created as internal by the compiler - which is why you need the line [assembly: InternalsVisibleTo("Cirrious.MvvmCross.WindowsPhone")]
Can you check that the AssemblyInfo.cs file definitely being linked into the project (and that this is the project containing the ViewModel/anonymous-class code)?
If that is the case, can you check the methodAccessException to see what the message is?
If that doesn't help, can you use a tool like Reflector to check the internalVisible attribute is actually present on the core/application assembly?