Permalink
Cannot retrieve contributors at this time
description | title | ms.date | f1_keywords | helpviewer_keywords |
---|---|---|---|---|
Compiler Error CS1061 |
Compiler Error CS1061 |
05/01/2021 |
CS1061 |
CS1061 |
Compiler Error CS1061
‘type’ does not contain a definition for ‘name’ and no accessible extension method ‘name’ accepting a first argument of type ‘type’ could be found (are you missing a using directive or an assembly reference?).
This error occurs when you try to call a method or access a class member that does not exist.
Example
The following example generates CS1061 because Person
does not have a DisplayName
method. It does have a method that is called WriteName
. Perhaps that is what the author of this source code meant to write.
public class Person { private string _name; public Person(string name) => _name = name; // Person has one method, called WriteName. public void WriteName() { System.Console.WriteLine(_name); } } public class Program { public static void Main() { var p = new Person("PersonName"); // The following call fails because Person does not have // a method called DisplayName. p.DisplayName(); // CS1061 } }
To correct this error
- Make sure you typed the member name correctly.
- If you have access to modify this class, you can add the missing member and implement it.
- If you don’t have access to modify this class, you can add an extension method.
See also
- The C# type system
- Extension Methods
I’m having a bit of a pain here and I just can’t figure out what’s wrong.
I have an ASP.net project which I deployed on a server. At first everything seemed allright, no Errors whatsoever. However, as a last adition I wanted to add a search function to a fairly large list so I added the following syntax to my mark-up:
<td>
Search Server:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="btnLookup" runat="server" OnClick="btnLookup_Clicked" Text="Search" />
<asp:Label ID="lblFeedback" runat="server" />
</td>
and the following in code behind:
protected void btnLookup_Clicked(object sender, EventArgs e)
{
lblFeedback.Text = "";
Session["IsSearch"] = true;
LoadServerList();
}
When I run this locally it works just fine as I expect.
HOWEVER!
When I copy these files to the server I get a compilation error:
Compiler Error Message: CS1061: ‘ ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx ‘ does not contain a definition for ‘btnLookup_ Clicked’ and no extension method ‘btnLookup_ Clicked’ accepting a first argument of type ‘ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx’ could be found (are you missing a using directive or an assembly reference?)
it says there is nothing that handles my Clicked event although it does work when I run it through Visual studio.
any ideas?
EDIT:
What I tried myself is
- renaming button
- deleting and readding the button
- add through designer
- renaming click event
- removing the event from markup allows normal execution … :/
- Remove From My Forums
-
Question
-
Hi Everyone,
I have an error message when I try to run my program, this is error CS1061 like show below. But actually my program is success full to run before.. But I don’t know why suddenly when I try to compile there’s any error :
—— Build started: Project: Latihan1, Configuration: Debug x86 ——
c:userslinadocumentsvisual studio 2010ProjectsLatihan1Latihan1Form1.Designer.cs(40,55): error CS1061: ‘Latihan1.Form1’ does not contain a definition for ‘Form1_Load’ and no extension method ‘Form1_Load’ accepting a first argument of type ‘Latihan1.Form1’
could be found (are you missing a using directive or an assembly reference?)Compile complete — 1 errors, 0 warnings
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Answers
-
It looks like you accidentally created a form Load event handler, then deleted it from code, but not the designer. To fix:
Open up your form in the designer, and go to the events in the properties page. Delete the «Form1_Load» event on the form’s Load…
Reed Copsey, Jr. — http://reedcopsey.com
If a post answers your question, please click «Mark As Answer» on that post and «Mark as Helpful«.-
Marked as answer by
Saturday, November 26, 2011 6:25 AM
-
Marked as answer by
Из первой формы через баттон вызывал вторую.
C# | ||
|
Во второй форме даже ничего написать не успел. Словил ошибку в Form2.Designer.cs
C# | ||
|
ошибка CS1061: «Statistics_square.Form2» не содержит определения для «Form2_Load» и не был найден метод расширения «Form2_Load», принимающий тип «Statistics_square.Form2» в качестве первого аргумента (возможно, пропущена директива using или ссылка на сборку)
И вроде читать умею, но что от меня хотят не догоняю.
__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
public class ShootEnemies : MonoBehaviour
{
public List<GameObject> enemiesInRange;
private float lastShotTime;
private MonsterData monsterData;
// Use this for initialization
void Start()
{
enemiesInRange = new List<GameObject>();
lastShotTime = Time.time;
monsterData = gameObject.GetComponentInChildren<MonsterData>();
}
// Update is called once per frame
void Update()
{
GameObject target = null;
// 1
float minimalEnemyDistance = float.MaxValue;
foreach (GameObject enemy in enemiesInRange)
{
float distanceToGoal = enemy.GetComponent<MoveEnemy>().DistanceToGoal();
if (distanceToGoal < minimalEnemyDistance)
{
target = enemy;
minimalEnemyDistance = distanceToGoal;
}
}
// 2
if (target != null)
{
if (Time.time - lastShotTime > monsterData.CurrentLevel.fireRate)
{
Shoot(target.GetComponent<Collider2D>());
lastShotTime = Time.time;
}
// 3
Vector3 direction = gameObject.transform.position - target.transform.position;
gameObject.transform.rotation = Quaternion.AngleAxis(
Mathf.Atan2(direction.y, direction.x) * 180 / Mathf.PI,
new Vector3(0, 0, 1));
}
}
private void OnEnemyDestroy(GameObject enemy)
{
enemiesInRange.Remove(enemy);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag.Equals("Enemy"))
{
enemiesInRange.Add(other.gameObject);
EnemyDestructionDelegate del =
other.gameObject.GetComponent<EnemyDestructionDelegate>();
del.enemyDelegate += OnEnemyDestroy;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag.Equals("Enemy"))
{
enemiesInRange.Remove(other.gameObject);
EnemyDestructionDelegate del =
other.gameObject.GetComponent<EnemyDestructionDelegate>();
del.enemyDelegate -= OnEnemyDestroy;
}
}
private void Shoot(Collider2D target)
{
GameObject bulletPrefab = monsterData.CurrentLevel.bullet;
// 1
Vector3 startPosition = gameObject.transform.position;
Vector3 targetPosition = target.transform.position;
startPosition.z = bulletPrefab.transform.position.z;
targetPosition.z = bulletPrefab.transform.position.z;
// 2
GameObject newBullet = (GameObject) Instantiate(bulletPrefab);
newBullet.transform.position = startPosition;
BulletBehavior bulletComp = newBullet.GetComponent<BulletBehavior>();
bulletComp.target = target.gameObject;
bulletComp.startPosition = startPosition;
bulletComp.targetPosition = targetPosition;
// 3
Animator animator =
monsterData.CurrentLevel.visualization.GetComponent<Animator>();
animator.SetTrigger("fireShot");
AudioSource audioSource = gameObject.GetComponent<AudioSource>();
audioSource.PlayOneShot(audioSource.clip);
}
}
Даже после того, как я почти полностью скопировал весь код игры по обучалке, у меня все равно не выходит запустить игру — выдает ошибку в приложенном коде:
AssetsShootEnemies.cs(60,68): error CS1061: 'MoveEnemy' does not contain a definition for 'DistanceToGoal' and no accessible extension method 'DistanceToGoal' accepting a first argument of type 'MoveEnemy' could be found (are you missing a using directive or an assembly reference?)
В чем проблема?
CS1061 – ‘{0}’ does not contain a definition for ‘{1}’ and no accessible extension method ‘{1}’ accepting a first argument of type ‘{0}’ could be found (are you missing a using directive or an assembly reference?)
Reason for the Error & Solution
‘type’ does not contain a definition for ‘name’ and no accessible extension method ‘name’ accepting a first argument of type ‘type’ could be found (are you missing a using directive or an assembly reference?).
This error occurs when you try to call a method or access a class member that does not exist.
Example
The following example generates CS1061 because Person
does not have a DisplayName
method. It does have a method that is called WriteName
. Perhaps that is what the author of this source code meant to write.
public class Person
{
private string _name;
public Person(string name) => _name = name;
// Person has one method, called WriteName.
public void WriteName()
{
System.Console.WriteLine(_name);
}
}
public class Program
{
public static void Main()
{
var p = new Person("PersonName");
// The following call fails because Person does not have
// a method called DisplayName.
p.DisplayName(); // CS1061
}
}
To correct this error
- Make sure you typed the member name correctly.
- If you have access to modify this class, you can add the missing member and implement it.
- If you don’t have access to modify this class, you can add an .