does anyone know where the error is? I've been looking for various solutions but I didn't get what I wanted
public static void LoadScene(int levelNum)
{
Application.backgroundLoadingPriority = ThreadPriority.High;
sceneToLoad = levelNum;
SceneManager.LoadScene(loadingSceneIndex);
}
Eror : Assets\Script AR\LoadingScreenManager.cs(35,32): error CS0103: The name 'loadingSceneIndex' does not exist in the current context
and one more problem this one
private void StartOperation(int levelNum)
{
Application.backgroundLoadingPriority = loadThreadPriority;
operation = SceneManager.LoadSceneAsync(levelNum, loadSceneMode);
if (loadSceneMode = LoadSceneMode.Single)
operation.allowSceneActivation = false;
}
Eror : Assets\Script AR\LoadingScreenManager.cs(91,13): error CS0029: Cannot implicitly convert type 'UnityEngine.SceneManagement.LoadSceneMode' to 'bool'
The first error happens because the variable loadingSceneIndex doesn't exist. You should plug the scene you want to load into the LoadScene function like this:
SceneManager.LoadScene(levelNum);
That way the LoadScene function knows which scene to load.
The second error happens because in you're if statement expects a bool, but plug in loadSceneMode = LoadSceneMode.Single. That is defining loadSceneMode. Instead, use loadSceneMode == LoadSceneMode.Single instead because that will return a bool.
Note: Have you looked into using something like Intellisense so your editor can detect these errors for you. If you are using Visual Studio, this link might help.
When i try to use Delegate's Method Property in C# i get this error.
'myDelegate' does not contain a definition for 'Method' and no
extension method 'Method' accepting a first argument of type
'myDelegate' could be found (are you missing a using directive or an
assembly reference?)
I really don't know the reason why i get this. My program is fairly simple and is based on delegates. Below it's code is given:
public delegate void myDelegate(int x);
public class Program
{
public void Main(string[] args)
{
X x = new X();
myDelegate d = x.InstanceProgress;
Console.WriteLine(d.Method);
}
}
class X
{
public void InstanceProgress(int percent) => Console.WriteLine(percent);
}
I get error on this line:
Console.WriteLine(d.Method);
See this image below, although i get the proper output but i get the error.
I have marked the error with green arrow on the image.
Looking at OP's screenshot. That looks like a Visual Studio error. And since it lets you build the it's not a true error. I don't get that error in VS2015.
I'd clean the solution and restart visual studio. That should clear it.
Old:
You'll want to do something like this:
X x = new X();
myDeligate d = x.InstanceProgress;
d.Invoke(5);
// or as Rahul pointed out you can simply use
d(5);
Invoke() is what actually calls the method. Until then the delegate is just a pointer to the method that you want to call.
I'm using VS2017 RC and my application targets net framework 4.6.1.
I have two assemblies referencing System.ValueTuple 4.3
MyProject.Services
MyProject.WebApi
In MyProject.Services I have a class with a method like this
public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync()
{
// Some code...
return (fCount, cCount, aCount);
}
In MyProject.WebApi I have a controller that use this method like that:
public async Task<HttpResponseMessage> GetInfoAsync()
{
// Some code...
var stats = await _myClass.GetAllStatsAsync();
var vm = new ViewModel
{
FCount = stats.fCount,
CCount = stats.cCount,
ACount = stats.aCount
};
return Request.CreateResponse(HttpStatusCode.OK, vm);
}
Intellisense is working and deconstruct the tuple but when I compile it fails without any Error in Error List window.
In the output windows I have this errors:
2>MyController.cs(83,31,83,40): error CS1061: 'ValueTuple' does not contain a definition for 'fCount' and no extension
method 'fCount' accepting a first argument of type 'ValueTuple' could be found (are you missing a using directive or an
assembly reference?) 2>MyController.cs(84,39,84,49): error CS1061:
'ValueTuple' does not contain a definition for 'cCount'
and no extension method 'cCount' accepting a first argument of type
'ValueTuple' could be found (are you missing a using
directive or an assembly reference?) 2>MyController.cs(85,35,85,40):
error CS1061: 'ValueTuple' does not contain a
definition for 'aCount' and no extension method 'aCount' accepting a
first argument of type 'ValueTuple' could be found (are
you missing a using directive or an assembly reference?)
I tried adding the DEMO and DEMO_EXPERIMENTAL build flags but still fails.
Any idea on what's wrong?
EDIT 1:
This code works and stats is well deconstructed. I'm probably hitting a bug.
public async Task<HttpResponseMessage> GetInfoAsync()
{
// Some code...
var stats = await _myClass.GetAllStatsAsync();
var tu = stats.ToTuple();
var vm = new ViewModel
{
FCount = tu.Item1,
CCount = tu.Item2,
ACount = tu.Item3
};
return Request.CreateResponse(HttpStatusCode.OK, vm);
}
EDIT 2:
Issue open on github here: https://github.com/dotnet/roslyn/issues/16200
If anyone falls in the same trap, to fix this you need to update this package:
Microsoft.Net.Compilers to 2.0 (you need to show pre-release)
I just want to add to the other answers.
Remove System.valuetuple from references. Otherwise, it doesn't work and I do not know why. Basically, value tuple is already in 4.7.2 and so if you use visual studio 2019 you're all set.
If you use visual studio 2019 and I did, that's what worked for me. I don't exactly know why. No need for nugget. No need to reference that directly.
Target your project to use .net framework 4.7.2 and remove references to valuetuple.
I think It is because you've not defined fCount, cCount and aCount. Try this
public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync()
{
// Some code...
//fCount, cCount, aCount are not defined here, so you should define them
var fCount = 0;
var cCount= 0;
var aCount = 0;
return (fCount , cCount, aCount );
//Other ways:
//return (fCount : 0, cCount: 0, aCount : 0);
//return new (int fCount , int cCount, int aCount ) { fCount = 0, cCount = 0, aCount = 0 };
}
public async Task<HttpResponseMessage> GetInfoAsync()
{
// Some code...
var stats = await _myClass.GetAllStatsAsync();
var vm = new ViewModel
{
FCount = stats.fCount,
CCount = stats.cCount,
ACount = stats.aCount
};
return Request.CreateResponse(HttpStatusCode.OK, vm);
}
Edited with #Swell suggestion
Take a look at this post
My problem was not at compile error, but during runtime.
But I suspect the fix is still valid and could help somebody here too.
After switching my project to .Net framework 4.7.2 I had to manually update the hintpath for System.ValueTuple from net461 to net47
<HintPath>..\Solutions\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
For the following code i am getting an error. How do i solve it? I just started android development and dont know anything much.
public override bool OnOptionsItemSelected(IMenuItem item)
{
Type thing = item.GetType();
String id = item.getItemId();}
Error CS1061: Type Android.Views.IMenuItem' does not contain a definition forgetItemId' and no extension method getItemId' of typeAndroid.Views.IMenuItem' could be found. Are you missing an assembly reference? (CS1061) (V002)
For Xamarin Android you have to use item.ItemId instead of item.getItemId()
If you need to cast it to string then:
if(item.ItemId.ToString() == "certainId")
{
//so something here..
}
I am making a game and I have a class called gameScripts. Inside gameScripts is a public void method called paintSquare. When this method is called,the method uses 2 if statements,and depending on which one is true,the squares image will be changed accordingly.
The problem is,when I try to use pictureBox.Image = Image.FromFile("cross.png"); to change the picture to a cross,pictureBox.Image gets a red line under it with the error message "Error 2 'System.Windows.Forms.Control' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?) c:\x\x\x\x\x\x\x\gameScripts.cs"
I have tried including System.Drawing and System.Windows.Forms in my namespaces,but I still get this error.
Any help would be appreciated,thanks.
The message 'ClassXXX' does not contain a definition for 'YYY' and no extension method 'YYY' accepting a first argument of type 'ClassXXX' could be found (are you missing a using directive or an assembly reference?) means literally what it says. Most likely in you code there is construction like this:
myObject.YYY
but the class, the instance of which the myObject is, does not have a member with name YYY.
For example:
class MyClass {
public string MyField;
}
...
var myObj = new MyClass();
myObj.MyField = "OK";
myObj.NotMyField = "FAIL"; // compiler will complain at this line
However, the compiler gets the list of available properties and methods by looking at the variable type. This may lead to the situation when the object itself have the member but compiler cannot see it as the variable is defined with a different type.
Consider the following code fragment:
class MyExtClass : MyClass {
public string MyNewField;
}
...
MyClass myObj = new MyExtClass();
myObj.MyField = "OK";
myObj.MyNewField = "FAIL"; // compiler will complain at this line
// because MyClass does not have it
So in your code the pictureBox is seems to be defined as System.Windows.Forms.Control. So even if it is, in fact, System.Windows.Forms.PictureBox, compiler cannot know it and stops with the error.