I've installed Unity Firebase SDK, firebase google-services and configured Player Settings with com project name. After that, I've written the following lines of code:
private DatabaseReference _databaseReference;
private string _userID;
private void Start()
{
_databaseReference = FirebaseDatabase.DefaultInstance.RootReference;
_userID = SystemInfo.deviceUniqueIdentifier;
}
Even though I followed the steps from the official documentation, I got an error:
DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your GetInstance() call.
Firebase.Database.FirebaseDatabase.GetInstance (Firebase.FirebaseApp app, System.String url)
Can someone help me please?
I've also tried adding FirebaseDatabase.GetInstance() but I get an error:
DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your GetInstance() call.
Firebase.Database.FirebaseDatabase.GetInstance
It looks like the Google-Service-info.plist or GoogleServices.json file that you're using doesn't include the correct database URL.
So work around that, specify the URL of the database in your GetInstance call:
_databaseReference = FirebaseDatabase.GetInstance("your database URL here").RootReference;
You can find the URL in the Firebase console for your database.
Related
I've created an Azure Function that retrieves new form inputs from a website, processes them and stores the result in another system by using an API call. I only want to retrieve the form inputs that have not been processed before. This is supported by the website.
I'm reading the timestamp of the most recent form input that has already been processed. This works fine.
I'm using the following function to read the setting from the Azure function environment:
private static string GetEnvironmentVariable(string name)
{
return System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}
After I've processed a form input, I store the timestamp of the form with the following function:
private static void SetEnvironmentVariable(string name, string value)
{
System.Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.Process);
}
Everything seems to be working fine. I see in the logs that form inputs don't get processed more than once. However, when I take a look at the environment variables in the Azure dashboard, I can see that the initial value of the variable is still present. This initial value will be used when the environment 'shuts down' and is restarted (e.g. after changing the value of another environment variable).
I've tried to change the target from 'Process' to 'Machine', but this results in access control errors. There are some questions on SO that are related to my issue, but none of them provides me with an answer for my situation.
I would like to know whether:
Environment variables are the / a suited solution for my use case;
If so, how can I prevent that a variable will be reset to its initial value after resetting the Azure environment.
Thanks in advance!
Firstly, the Environment.SetEnvironmentVariable method already worked in your case.
Here is an answer from Hury Shen:
When you set the variable by Environment.SetEnvironmentVariable, it
will not show in application setting. But we can use it by
Environment.GetEnvironmentVariable as expected. Although the solution
you mentioned is not so good, but it can implement your requirement.
The adverse effect is when you restart the function app, the variables
will be lost.
About the target Machine: The environment variable is stored or retrieved from the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment key in the Windows operating system registry. This value should be used on .NET implementations running on Windows systems only.
One way to achieve but not set inside code:
In App Service, you can set app settings outside of your app code.
Then you can access them in any class using the standard ASP.NET Core
dependency injection pattern:
using Microsoft.Extensions.Configuration;
namespace SomeNamespace
{
public class SomeClass
{
private IConfiguration _configuration;
public SomeClass(IConfiguration configuration)
{
_configuration = configuration;
}
public SomeMethod()
{
// retrieve nested App Service app setting
var myHierarchicalConfig = _configuration["My:Hierarchical:Config:Data"];
// retrieve App Service connection string
var myConnString = _configuration.GetConnectionString("MyDbConnection");
}
}
}
I'm attempting to integrate GrapQL.EntityFramework using a DB first approach on an Azure Function. I've generated the needed contexts, User graphs, query, along with the function itself. Currently I'm having an issue with the Startup file of my function app where I am to use dependency injection.
I've attempted both options on the configuration guide in the GraphQL.EntityFramework Docs. I've also made attempts at snippets of code such as builder.Services.AddSingleton(typeof(IEfGraphQLService<PersonarDBContext>),instance => { return new DBContext(); });
The current state of my startup file
public override void Configure(IFunctionsHostBuilder builder)
{
string connection = ""
builder.Services.AddTransient<UserQuery>();
builder.Services.AddDbContext<DBContext>(options => options.UseSqlServer(connection));
var optionBuilder = new DbContextOptionsBuilder<DBContext>();
optionBuilder.UseSqlServer(connection);
EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);
builder.Services.AddSingleton(typeof(IEfGraphQLService<DBContext>),instance => { return new DBContext(); });
}
At this point in time I am just attempting to get my function app to startup properly. I am currently experiencing this error output.
User: Microsoft.Azure.WebJobs.Host: Error indexing method 'User'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'service' to type IEfGraphQLService`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Likely worth opening an issue on GitHub but my suspicion is whatever the library is trying to auto-register here is throwing the exception
EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);
I'm trying to use Auth0 for my mobile application (Xamarin) and I've been following the quickstart guide provided by Auth0.
I've installed the component via Xamarin market (Visual Studio) and to do the integration, I've created a class file dedicated to Auth0 related operations. I copied and pasted the provided code from the quick start guide but visual studio returns this error:
The contextual keyword 'var' may only appear within a local variable declaration or in script code
The code provided used var instead of a normal variable so I'm not sure what I can substitute with it:
using Auth0.SDK;
namespace Application
{
class LoginHandler
{
var auth0 = new Auth0Client(
"*************",
"************************");
}
}
I'm not sure what I'm doing wrong, I'd also like some help implementing the Login UI as the Xamarin guides are deathly outdated.
Short answer: You can use Auth0Client instead of var.
internal class LoginHandler
{
private Auth0Client auth0 = new Auth0Client("***", "*****");
}
Long answer:
The snippet is assuming you would use the Auth0 client instance in a context where it would be considered a local variable and as such it would be valid code. For example:
internal class LoginHandler
{
public void HandleLogin()
{
var auth0 = new Auth0Client("***", "*****");
// ...
}
}
If you require assistance in solving other specific issues then you should post specific questions that clearly illustrate the problem you're having.
I'm following this OData V4 tutorial and now have a problem with the bound function MostExpensive.
This function is bound to the Productscollection and is registered in WebApiConfig.Register() like suggested in the tutorial:
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "ProductService";
builder.EntityType<Product>().Collection.Function("MostExpensive").Returns<decimal>();
There is only described a rudimentary client for this service in part 2 of this tutorial. So I want to extend it so that I also can call the functions described in the later parts of the tutorial.
I have created the client using OData Client Code Generator as suggested in the tutorial. I then add some products and suppliers and then want to get the most expensive product:
static void Main(string[] args)
{
const string serviceUri = "http://localhost:52542";
Container container = new Container(new Uri(serviceUri));
AddProducts(container, GenerateSomeProducts());
AddSuppliers(container, GenerateSomeSuppliers());
Console.WriteLine("Most expensive product is: {0}", container.Products.MostExpensive().GetValue());
...
}
When calling GetValue() I am getting an InvalidOperationException stating that http://localhost:52542/$metadata refers to a Edm.Decimal type but a Collection(Edm-Decimal) type is expected.
When calling http://localhost:52542/Products/ProductService.MostExpensive() directly in the browser I'm getting
{
"#odata.context":"http://localhost:52542/$metadata#Edm.Decimal","value":40000.95
}
Which seems to be correct.
Do I do anything wrong? I have no idea how to fix this. So any suggestions about that?
I guess you are using T4 2.2.0, right?
There is a bug in T4 2.2.0 which causes this issue. You can use the content in following link to replace your ttinclude file and regenerate your proxy to work around the issue.
https://raw.githubusercontent.com/LaylaLiu/odata.net/T4TempFix/src/CodeGen/ODataT4CodeGenerator.ttinclude
I've downloaded the latest SignalR code (as of 04/04/12) from GitHub as it now compiles with MonoDevelop so I can use it on OS X.
But while testing the new version with the SignalR.Sample example listed on the Getting Started page, it fails with the following error:
The name 'AspNetHost' does not exist in the current context
This occurs in StockTicker.cs here:
private static dynamic GetClients()
{
return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<StockTickerHub>();
}
Can anyone explain what has become of AspNetHost?
Suggestions on how to get the SignalR.Sample compiling would be very welcome.
I had the same problem and found that this was deprecated in SignalR 0.5. Here is an article detailing the changes.
Specific to your item, the change is from this:
public void PerformLongRunningHubOperation()
{
var clients = AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<MyHub>();
clients.notify("Hello world");
}
To this in 0.5:
public void PerformLongRunningHubOperation()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.notify("Hello world");
}
You're gonna need to read the code because the source isn't in sync with the docs. The docs are for the current release, not the actively developed.
Take a look at the asp.net sample to see the current API. It's not set in stone yet though.