ViewState syntax error in visual studio 2012? - c#

I get a strange error message when using viewState on a web page. Using example code from Microsoft generates this error on ViewState["Text"]:
Error 17 Cannot apply indexing with [] to an expression of type
'method group'
It seems the error is not in the code, but in config or something.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using OfficeOpenXml;
using vaCommonLibrary;
public partial class lista : System.Web.UI.Page
{
public String Text
{
get
{
object o = ViewState["Text"];
return (o == null)? String.Empty : (string)o;
}
set
{
ViewState["Text"] = value;
}
}
I get another error further down in my code:
ViewState["SortDirection"] = sortDirection;
gives
Error 1 Invalid token '[' in class, struct, or interface member
declaration

Problem solved.
Your second error sounds like that code isn't in the right place
Absolutely correct. The code was right, but further down in my code there was a { missing after an IF-statement, which caused later parentheses to mismatch leading to "strange" errors. I should have seen that, but I'm kind of new to C#, and just started to migrate all my VB.NET code to C#.
Thanks.

Related

Syntax Error 'Helper' does not exist in the current context

I am building a form where i can drag and drop button controls.
I followed the tutorial from this link but the code generates an error difficult for me to debug.
Syntax Error
Error code CS1030, "The name 'Helper' does not exist in the current
context
I have tried adding and removing namespaces, using System and using System.Drawing but the same error code is still present.
In a much more extensive code like the actual example, Helper.ControlMover does work, and it is very easy to use. What exactly am i missing in the code below?
Thank you for your time and help.
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;
namespace MovingControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Helper.ControlMover.Init(this.button1);
}
}
}

ˋ[System.Version]::Parse('')´ error in Xamarin

I have been trying to create a custom control on Xamarin.Forms.
My solution builds just fine on UWP but with android I always get the same error :
Impossible to evaluate the expression "[System.Version]::Parse('')". String is either too long or too short.
How Can I solve this ???
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using App2;
using App2.UWP;
using Xamarin.Forms.Platform.UWP;
using Windows.UI.Xaml.Controls;
[assembly: ExportRenderer(typeof(NavigationPannel), typeof(NavigationPannelRenderer))]
namespace App2.UWP
{
class NavigationPannelRenderer : ViewRenderer<NavigationPannel, NavigationView>
{
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPannel> args)
{
base.OnElementChanged(args);
if (Control == null)
{
NavigationView nav_view = new NavigationView();
nav_view.MenuItems.Add(new NavigationViewItem
{
Content = "My content",
Icon = new SymbolIcon(Symbol.Folder),
Tag = "content"
});
SetNativeControl(nav_view);
}
}
}
}
EDIT :
I made another solution and tried to redo everything step by step, my android project compiled just fine at first, but when I Added my UWP custom renderer, and after compiling it on Windows, it started showing the same error
Okay so I made it step by step again copy/pasting line by line for a third time and this time no error occurs.
I really don't know what happened here so if anyone has any idea i would still gladly accept it.

WHMCS C# Authentication

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 = “....”

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.

C# Blocking IP by modifying Windows 7 Firewall

I'm starting to build an anti-ddos application in C#, it's going to block IP's by checking how many connections there are, in an amount of time, but I can't find whats needed for NetFwMgrType.
Here's code, I just started:
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 NETCONLib;
using NATUPNPLib;
using NetFwTypeLib;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
bool Firewallenabled = mgr.LocalPolicy.CurrentProfile.FirewallEnabled;
public Form1()
{
InitializeComponent();
}
}
}
The errors I get is:
Error 1 A field initializer cannot reference the non-static field, method, or property 'WindowsFormsApplication1.Form1.NetFwMgrType'
Error 2 A field initializer cannot reference the non-static field, method, or property 'WindowsFormsApplication1.Form1.mgr'
(I added references: \Windows\System32\hnetcfg.dll and \Windows\System32\FireWallAPI.dll)
Thanks for answer.
Oh and if you know how to block IPs with Firewall modifying, as well, it would save me a lot of googling:)

Categories

Resources