WHMCS C# Authentication - c#

I'm trying to develope a C# application to send an authentication request to the server. I can do it with php application being ran from a web browser but not using visual studio in a class.
I made a class which is suppose to declare what $whmcsUrl is. https://developers.whmcs.com/api/sample-code/ This is where i am trying to copy from.
My class looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace freeze_uk
{
class whmcsUrl
{
whmcsUrl = "https://www.frezee.uk/client/";
}
}
It says:
Error CS1519 Invalid token '=' in class, struct, or interface member declaration
Why can't I use this?
Is what I'm trying to do even possible?
Thanks,
James

Add variable type
string whmcsUrl = “....”

Related

Visual Studio / RestSharp - Cannot navigate to the symbol under the caret (CS0118)

I have only been coding for about two years now (off and on) but I'm well acquainted with this cryptic error across multiple versions of VS. I know this issue isn't related to just RestSharp.
This 'caret error' has been the bane of my VS experience so that is why I'm here.
Environment:
Microsoft Visual Studio Community 2019 Version 16.8.1
RestClient v4.0.30319
Windows 10 Professional
What I'm trying to do:
I'm following the very simple directions on the RestClient site. I have installed RestClient, added references but when I try to get started I get that dreaded caret error.
None of this is my code aside from the reference to RestClient, which may or may not be appropriate (I don't know).
Screen Snip
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RestSharp;
using RestSharp.Authenticators;
using RestClient;
namespace newDawn2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var client = new RestClient("https://api.twitter.com/1.1");
client.Authenticator = new HttpBasicAuthenticator("username", "password");
var request = new RestRequest("statuses/home_timeline.json", DataFormat.Json);
var response = client.Get(request);
}
}
}
Thanks for reading.
using RestClient;
Here you are declaring that you are using the namespace RestClient, not the object.
var client = new RestClient(...
The error is raised here because you are trying to create an instance of the namespace you just declared you were using.
It's uncommon and confusing for an object to share a name with part of its namespace, so you should generally not expect to see a using statement with the same name you use to create an object.
Namespaces are used to separate, organize classes and limit what classes are loaded at compile time.
Classes of the same name can exist in different namespaces.
You could create your own class named RestClient and use it in this project as well(maybe for testing) as long as they existed in different namespaces. The full declaration of the class you are using now is RestSharp.RestClient. You could create a class with the full declaration Facundo.Test.RestClient and use them both in the same project. However, in this case, you could not use using statements and everytime you wanted to instantiate one or the other you would need to fully declare the namespace
RestSharp.RestClient client = new RestSharp.RestClient(...);
or
Facundo.Test.RestClient testClient = new Facundo.Test.RestClient(...);
I would not recommend naming them the same in practice, just trying to illustrate namespaces.

Cant recognize class in webform project

In my web form project I opened a folder called App_Code inside that folder I have class named Test123, but when I try to create instance inside WebForm1.aspx.cs it doesn't recognize that type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StephanProject_2.App_Code
{
public class Test123
{
}
}
My project structure:
I tried to add using StephanProject_2.App_Code;
What's the problem?
The class you are calling does not seem to be in the same namespace as the Webform1 class
if its from another namespace use.
StephanProject_2.App_Code.Test123 t = new StephanProject_2.App_Code.Test123()
Or alternatively in the top say
using StephanProject_2.App_Code;
When i try to same as your project then it works my code
You can see Here

Issues with Intellisense and class library

I am using Visual Studio 2013. I am trying to start unit testing by using this tutorial.
I have added a class library and a reference to MVC. However, the Intellisense/Autocompletion is not working properly within my class library. Currently, this is all the code I have in my test class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using System.Web.Mvc;
using System.Web;
using Application_Portal;
using Application_Portal.Controllers;
namespace ApplicationPortalTests
{
[TestFixture]
public class HomeControllerTest
{
HomeController home = new HomeController();
}
}
The Intellisense does not seem to recognize the home variable (no suggested properties, etc.) Typing home.Index() gives the following error:
ApplicationPortalTests.HomeControllerTest.home' is a 'field' but is used like a 'type'
Furthermore, it does not even seem to recognize "var" (as in var result = ...). Instead, when I type var and hit space, it autocompletes it as EnvironmentVariableTarget.
I have tried cleaning and rebuilding the project, and closing and reopening Visual Studio, but with no success.
What might the issue be? I appreciate any advice.
You have declared your variable inside the class. If you want to use this variable, it must be within the context of a member. For instance:
[Test]
public void test_my_index_page()
{
var result = home.index();
}

"Name 'Process' does not exist in current context" error in console app

I'm trying to use the Process class but it gives me this compiler error every time I do
The name 'Process' does not exist in the current context
I've already added using System.Diagnostics; at the top of my code but I still get this error. Autocomplete wont even recognize the class.
Hear is the code. I've only included the Main method because the rest of the code has nothing to do with the error.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
public class MainClass
{
static void Main()
{
AIRuntime adam = new AIRuntime("Adam", false);
adam.AIUpdate();
Process.Start(adam.directory); //adam.directory is just a string
}
}
My IDE is Xamarin Studio if it matters.
After web searching and attempts, I found the problem.
To fix this, I manually add a reference to System in my project options instead of just typing using System;. I also need to keep using System.Diagnostics; at the top. It's all in the picture below
Thanks guys for trying to help

WPF User Control Error

I've search the forum, but I coundn't find anything that quite satisfied me.
In Microsoft Visual Studio 2010, when I try to add a WPF User Control I get this error:
"Value cannot be null. Parameter name: objectType"
Then when I want to select the hosted content, I get this error :
"An error occured trying to add references for type 'PolyPuttZe.GameCanvas', or finding the type. Make sure the project references are correct."
I followed this tutorial : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms
Thanks!
EDIT:
This is the code I wrote :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace PolyPuttZe
{
public partial class Game : Form
{
public Game()
{
InitializeComponent();
}
}
}
Here's a more useful answer for the next person that has this issue - you need to create your WPF user control and build the solution first. Then open/create the form and add an Element Host and set it to your control. This is likely what the accepted answer means as starting over would work as well if you create the WPF control first.

Categories

Resources