I’m new to coding, and from what I gathered, the following code was written to be compatible with C# 4.0 not the current version. There is also another error that I couldn’t fit in the title:
Invalid token ‘;’ in class, struct, or interface member declaration
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camera_controller : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
Vector3 offset = transform.position;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void LateUpdate ()
{
transform.position=player.transform.position+offset;
}
}
Selvin
6,6303 gold badges38 silver badges43 bronze badges
asked Nov 9, 2019 at 1:38
1
You need to define a type for the variable.
transform.position is the type Vector3.
try this:
Vector3 offset = transform.position;
answered Nov 9, 2019 at 1:49
2
You should remove Vector3 offset = transform.position;
and add offset = transform.position;
under Start()
or Awake()
and see below link for more info. C# does not allow field initializers besides constants, constructors and static fields. transform.position
is a non-static field.
Why can’t I assign transform.position to a Vector3 object?
answered Nov 9, 2019 at 9:36
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Compiler Error CS1519 |
Compiler Error CS1519 |
07/20/2015 |
CS1519 |
CS1519 |
186cef8e-c6c7-49aa-8b43-f6c2cb628414 |
Compiler Error CS1519
Invalid token ‘token’ in class, struct, or interface member declaration
This error is generated whenever a token is encountered in a location where it does not belong. A token is a keyword; an identifier (the name of a class, struct, method, and so on); a string, character, or numeric literal value such as 108, «Hello», or ‘A’; or an operator or punctuator such as ==
or ;
.
Any class, struct, or interface member declaration that contains invalid modifiers before the type will generate this error. To fix the error, remove the invalid modifiers.
The following sample generates CS1519 in five places because tokens are placed in locations where they are not valid:
// CS1519.cs // Generates CS1519 because a class name cannot be a number: class Test 42 { // Generates CS1519 because of 'j' following 'I' // with no comma between them: int i j; // Generates CS1519 because of "checked" on void method: checked void f4(); // Generates CS1519 because of "num": void f5(int a num){} // Generates CS1519 because of namespace inside class: namespace; }
See also
- Classes
- Structure types
- Interfaces
- Methods
Ошибка парсера CS1519 при запуске скрипта
Используется csharp
using UnityEngine;
public class BirdHelper : MonoBehaviour
{
public float force;
private new Rigidbody2D rigidbody;
<span style=«font-weight: bold»>private GameHelper;</span>
void Awake()
{
rigidbody = GetComponent<Rigidbody2D>();
gameHelper = Camera.main.GetComponent<GameHelper>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
rigidbody.AddForce(Vector2.up * (force — rigidbody.velocity.y), ForceMode2D.Impulse);
rigidbody.MoveRotation(rigidbody.velocity.y * 2.0F);
}
void OnCollisionEnter2D (Collision2D collision)
{
gameHelper.restartButton.gameObject.SetActive(true);
Time.timeScale = 0.0F;
}
void OnTriggerExit2D (Collider2D other)
{
gameHelper.score++;
}
}
Этот скрипт с Хабра, рабочий.У меня в MonoDevelop после билда скрипта выходит ошибка в выделенной строке: Error CS1519: Недопустимая лексема «;» в объявлении класса, структуры или интерфейса (CS1519) (Assembly-CSharp).С чем может быть связана и можно ли исправить?
- evks
- UNец
- Сообщения: 9
- Зарегистрирован: 14 фев 2020, 07:59
Re: Ошибка парсера CS1519 при запуске скрипта
samana 19 мар 2020, 21:10
Видимо в оригинале ошибка, так как упущено имя для переменной, должно быть примерно так
Используется csharp
private GameHelper имяПеременной;
в оригинале это имя было такое gameHelper ( с маленькой буквы). Правда там тоже оно упущено при объявлении, но используется в коде.
-
samana - Адепт
- Сообщения: 4733
- Зарегистрирован: 21 фев 2015, 13:00
- Откуда: Днепропетровск
Re: Ошибка парсера CS1519 при запуске скрипта
evks 19 мар 2020, 22:45
Спасибо покопаю в эту сторону.
- evks
- UNец
- Сообщения: 9
- Зарегистрирован: 14 фев 2020, 07:59
Re: Ошибка парсера CS1519 при запуске скрипта
Tolking 20 мар 2020, 01:09
private new Rigidbody2D rigidbody;
Ковчег построил любитель, профессионалы построили Титаник.
-
Tolking - Адепт
- Сообщения: 2684
- Зарегистрирован: 08 июн 2009, 18:22
- Откуда: Тула
Re: Ошибка парсера CS1519 при запуске скрипта
evks 21 мар 2020, 18:35
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdHelper : MonoBehaviour
{
public float force;
private new Rigidbody2D rigidbody;
private GameHelper gameHelper;
void Awake()
{
rigidbody = GetComponent<Rigidbody2D>();
gameHelper = Camera.main.GetComponent<GameHelper>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
rigidbody.AddForce(Vector2.up * (force — rigidbody.velocity.y), ForceMode2D.Impulse);
rigidbody.MoveRotation(rigidbody.velocity.y * 2.0F);
}
void OnCollisionEnter2D (Collision2D collision)
{
gameHelper.restartButton.gameObject.SetActive(true);
Time.timeScale = 0.0F;
}
void OnTriggerExit2D (Collider2D other)
{
gameHelper.score++;
}
}
Да, вот так работает, спасибо
- evks
- UNец
- Сообщения: 9
- Зарегистрирован: 14 фев 2020, 07:59
Вернуться в Почемучка
Кто сейчас на конференции
Сейчас этот форум просматривают: Google [Bot] и гости: 31
jour_trau 0 / 0 / 0 Регистрация: 08.04.2022 Сообщений: 1 |
||||
1 |
||||
08.04.2022, 15:23. Показов 1046. Ответов 3 Метки нет (Все метки)
RotateCamera.cs(9,1): error CS1519: Invalid token ‘}’ in class, struct, or interface member declaration
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
08.04.2022, 15:23 |
Ответы с готовыми решениями: Error 1 Invalid token ‘=’ in class, struct, or interface member declaration public string firstName; Ошибка в скрипте Unity: Unexpected symbol in class, struct, or interface member declaration ошибка CS1519 unexpected symbol 0.2 in class, stuct or interface member declaration Ошибка «Unexpected symbol in class, struct, or interface member declaration» Error: Expected class, delegate, enum, interface, or struct 3 |
610 / 375 / 134 Регистрация: 06.03.2017 Сообщений: 1,377 |
|
08.04.2022, 15:34 |
2 |
private Transform Это что за чушь?
0 |
filh 53 / 37 / 19 Регистрация: 11.06.2021 Сообщений: 152 |
||||
08.04.2022, 15:39 |
3 |
|||
0 |
filh 53 / 37 / 19 Регистрация: 11.06.2021 Сообщений: 152 |
||||
08.04.2022, 16:49 |
4 |
|||
Pilarentes, который компилится:
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
08.04.2022, 16:49 |
Помогаю со студенческими работами здесь Error CS1518: Expected class, delegate, enum, interface, or struct Выдает ошибку: incorrect field declaration in class TForm1 Delphin выдает ошибку при создании отчета Invalid use of keyword.Token: , Line Number: 1 Как исправить ошибку error C2230: «a member function of a managed class cannot return a non-managed class» Помогите пожалуйста исправить ошибку
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 4 |
CS1519 – Invalid token ‘{0}’ in class, record, struct, or interface member declaration
Reason for the Error & Solution
Invalid token ‘token’ in class, struct, or interface member declaration
This error is generated whenever a token is encountered in a location where it does not belong. A token is a keyword; an identifier (the name of a class, struct, method, and so on); a string, character, or numeric literal value such as 108, «Hello», or ‘A’; or an operator or punctuator such as ==
or ;
.
Any , struct, or interface member declaration that contains invalid modifiers before the type will generate this error. To fix the error, remove the invalid modifiers.
The following sample generates CS1519 in five places because tokens are placed in locations where they are not valid:
// CS1519.cs
// Generates CS1519 because a class name cannot be a number:
class Test 42
{
// Generates CS1519 because of 'j' following 'I'
// with no comma between them:
int i j;
// Generates CS1519 because of "checked" on void method:
checked void f4();
// Generates CS1519 because of "num":
void f5(int a num){}
// Generates CS1519 because of namespace inside class:
namespace;
}
Line 313: #line default
Line 314: #line hidden
Line 315: @__w.Write("rn</table>rn"); Line 316: }
Line 317:
C:Program Files (x86)Common FilesMicrosoft SharedDevServer10.0> "C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe" /t:library /utf8output /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Corev4.0_4.0.0.0__b77a5c561934e089System.Core.dll" /R:"C:WindowsMicrosoft.NETFrameworkv4.0.30319mscorlib.dll" /R:"C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921assemblydl380ea105dcea80408_2f85cd01TeamPortal.DLL" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Xmlv4.0_4.0.0.0__b77a5c561934e089System.Xml.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Data.Entityv4.0_4.0.0.0__b77a5c561934e089System.Data.Entity.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.WorkflowServicesv4.0_4.0.0.0__31bf3856ad364e35System.WorkflowServices.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_32System.EnterpriseServicesv4.0_4.0.0.0__b03f5f7f11d50a3aSystem.EnterpriseServices.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ServiceModelv4.0_4.0.0.0__b77a5c561934e089System.ServiceModel.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Activitiesv4.0_4.0.0.0__31bf3856ad364e35System.Activities.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ComponentModel.DataAnnotationsv4.0_4.0.0.0__31bf3856ad364e35System.ComponentModel.DataAnnotations.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ServiceModel.Activitiesv4.0_4.0.0.0__31bf3856ad364e35System.ServiceModel.Activities.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Configurationv4.0_4.0.0.0__b03f5f7f11d50a3aSystem.Configuration.dll" /R:"C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_global.asax.d89cadyu.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.Extensionsv4.0_4.0.0.0__31bf3856ad364e35System.Web.Extensions.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_32System.Datav4.0_4.0.0.0__b77a5c561934e089System.Data.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Drawingv4.0_4.0.0.0__b03f5f7f11d50a3aSystem.Drawing.dll" /R:"C:WindowsassemblyGAC_MSILMicrosoft.ReportViewer.WebForms10.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.WebForms.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystemv4.0_4.0.0.0__b77a5c561934e089System.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.Abstractionsv4.0_4.0.0.0__31bf3856ad364e35System.Web.Abstractions.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.Routingv4.0_4.0.0.0__31bf3856ad364e35System.Web.Routing.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ServiceModel.Activationv4.0_4.0.0.0__31bf3856ad364e35System.ServiceModel.Activation.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ServiceModel.Webv4.0_4.0.0.0__31bf3856ad364e35System.ServiceModel.Web.dll" /R:"C:WindowsassemblyGAC_MSILMicrosoft.ReportViewer.Common10.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.Common.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.IdentityModelv4.0_4.0.0.0__b77a5c561934e089System.IdentityModel.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Data.DataSetExtensionsv4.0_4.0.0.0__b77a5c561934e089System.Data.DataSetExtensions.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.DynamicDatav4.0_4.0.0.0__31bf3856ad364e35System.Web.DynamicData.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILMicrosoft.CSharpv4.0_4.0.0.0__b03f5f7f11d50a3aMicrosoft.CSharp.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Runtime.Serializationv4.0_4.0.0.0__b77a5c561934e089System.Runtime.Serialization.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Deploymentv4.0_2.0.0.0__31bf3856ad364e35System.Web.WebPages.Deployment.dll" /R:"C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921assemblydl37b0734df2ec99241_5c16cd01AntiXSSLibrary.DLL" /R:"C:WindowsassemblyGAC_MSILSystem.Web.Mvc2.0.0.0__31bf3856ad364e35System.Web.Mvc.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_32System.Webv4.0_4.0.0.0__b03f5f7f11d50a3aSystem.Web.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.Servicesv4.0_4.0.0.0__b03f5f7f11d50a3aSystem.Web.Services.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Xml.Linqv4.0_4.0.0.0__b77a5c561934e089System.Xml.Linq.dll" /R:"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.ApplicationServicesv4.0_4.0.0.0__31bf3856ad364e35System.Web.ApplicationServices.dll" /out:"C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.dll" /D:DEBUG /debug+ /optimize- /win32res:"C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921o1xfcg2q.res" /w:4 /nowarn:1659;1699;1701 /warnaserror- "C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.0.cs" "C:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.1.cs"
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved.
c:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.0.cs(315,23): error CS1519: Invalid token '(' in class, struct, or interface member declaration
c:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.0.cs(319,28): error CS1518: Expected class, delegate, enum, interface, or struct
c:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.0.cs(325,1): error CS1022: Type or namespace definition, or end-of-file expected
c:UsersarchnamAppDataLocalTempTemporary ASP.NET Filesroot7b463e16aedbc921App_Web_openspaordersdetail.ascx.34671b6c.fno3v11e.0.cs(318,59): error CS0106: The modifier 'override' is not valid for this item
My view is very simple that it is complaining about. Here it is:
<%@
Control
Language=»C#»
Inherits=»TeamPortal.Infrastructure.TeamPortalViewUserControl<TeamPortal.Models.OpenSpaOrdersModel>»
%>
<%//AM
8/20/12 added this view with SpaOrderController.cs to show Open Spa orders on Teamportal dashboard
%>
<hr
/>
<table>
<tr>
<td>
<table>
<thead>
<tr>
<th
style=»text-align:left»>Status</th>
<th
style=»text-align:left»>Order</th>
<th
style=»text-align:left»>PO
#</th>
<th
style=»text-align:left»>Description
#</th>
<th
style=»text-align:left»>Model
#</th>
<th
style=»text-align:left»>Qty
#</th>
<th
style=»text-align:left»>QtyBo
#</th>
<th
style=»text-align:left»>Scheduled
#</th>
<th
style=»text-align:left»>Ship
Method</th>
<th
style=»text-align:left»>Order
Date</th>
</tr>
</thead>
<%foreach
(var
order in
Model.OpenSpaOrders) {%>
<tr>
<td><%:
order.Status%></td>
<td><%:
order.OrderNumber%></td>
<td><%:
order.PurchaseOrderNumber%></td>
<td><%:
order.Description%></td>
<td><%:
order.Model%></td>
<td><%:
order.Quantity%></td>
<td><%:
order.QtyBackOrdered%></td>
<td><%:
order.Scheduled.ToShortDateString()%></td>
<td><%:
order.ShipMethod%></td>
<td><%:
order.OrderDate.ToShortDateString()%></td>
</tr>
<%}%>
</table>
</td>
</tr>
</table>
This one has cropped up a couple of times in my development activities recently, but with just enough of a gap for me to have forgotten the solution and I had to figure it out again.
It happens in situations where the project worked fine a minute ago and then all of a sudden the project wont run. It has also happened in situations where I have made a small update and then some seemingly unrelated part of the site has broken.
From researching the problem it seems to hint at the server not having the LINQ libraries installed or missing references but from investigation of the projects I found they were both installed and referenced correctly.
It turns out that, for me at least, it was a very simple fix. All you have to do is:
- Find the file that is now complaining
- Open it up in Visual Studio
- Press the space bar and then delete the character you typed
- Save the file
- Upload the file to the website
- Revisit the website
These steps simply «dirty» the file in the eyes of the asp.net compiler and forces it to recompile the website again the next time a visitor requests a page.
My theory as to what is going wrong is that when the previous update caused a recompile the old assemblies are locked and in use / not deleted / forgot about somehow so the next time it tries to run it has two many conflicting assemblies and crashes. That is about as much detail as I can go into though because I am just guessing.
If this article has not solved your problem then the following link could be useful which describes an alternative fix for the problem. It revolves around the fact that you might not have referenced the LINQ libraries correctly:
- http://forums.asp.net/t/1222718.aspx