I have downloaded the Roslyn CTP and have run across the following error.A CompilationErrorException is thrown when executing the line session.Execute(#"using System.Linq;"); with the following message:
(1,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
My code is:
namespace RoslynError
{
using System;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;
internal class RoslynError
{
static void Main(string[] args)
{
var engine = new ScriptEngine();
Session session = engine.CreateSession();
session.Execute(#"using System.Collections;");
session.Execute(#"using System.Linq;");
Console.ReadKey();
}
}
}
I'm especially confused as to why the System.Linq line throws an error while System.Collections is fine.
The engine needs a reference to the assembly that the System.Linq namespace is in (System.Core.dll)
engine.AddReference(typeof(System.Linq.Enumerable).Assembly.Location);
This needs to be done before the session is created.
Related
I have installed Microsoft.azure.data nuget package in visual studio but I m getting below error-
Program.cs(1,17): error CS0234: The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) below is my program code -
using Microsoft.Azure.Kusto.Data;
using System;
namespace LensDashboradOptimization
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
//var clusterUrl = "https://mykusto.kusto.windows.net";
// replace 'WithAadUserPromptAuthentication' with your preferred method of authentication
//var kcsb = new Kusto.Data.KustoConnectionStringBuilder(clusterUrl);
//Console.WriteLine(kcsb);
// Read the first row from reader -- it's 0'th column is the count of records in MyTable
// Don't forget to dispose of reader when done.
var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://help.kusto.windows.net/Samples;Fed=true");
var reader = client.ExecuteQuery("StormEvents | count");
Console.WriteLine(reader);
}
}
}
Install Microsoft.Azure.Kusto.Data nuget. then it compiles for me. It does give me authentication errors but not assembly reference errors.
using Kusto.Data.Net.Client;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var client = KustoClientFactory.CreateCslQueryProvider("https://help.kusto.windows.net/Samples");
var reader = client.ExecuteQuery("StormEvents | count");
}
}
}
I've got a Xamarin.Forms app to dynamically compile c# code on a button press, but I get errors in the code.
This is the code for the button being pressed:
{
string text = ((Editor)sender).Text;
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "foo.exe", true);
parameters.GenerateExecutable = true;
CompilerResults results = csc.CompileAssemblyFromSource(parameters, text);
results.Errors.Cast<CompilerError>().ToList().ForEach(error => string errors = error.ErrorText;
}
and I am using:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
With the XAML being this:
<Button x:Name="compilebutton" Text="Compile" Clicked="oncompile" />
The type or namespace name 'CompilerParameters' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CompilerResults' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CompilerError' could not be found (are you missing a using directive or an assembly reference?)
I have tested this without Xamarin.Forms in a Console Application and it worked fine, i'm not sure what the issue is, any help would be appreciated, thanks!
I just begin a test with CoreCRL. I could compile and run the HelloWorld.cs example. But when I add some extra function to make it more really, this is my code:
using System;
namespace BenchMark
{
class Program
{
/*******************************************************************************/
public static void Main()
{
try
{
Console.WriteLine("BenchMark.exe C# runned");
string[] param = System.Environment.GetCommandLineArgs();
var benchMarkType = param[1];
switch (benchMarkType)
{
case "alg":
PhepToanDaiSo p = new PhepToanDaiSo();
p.callAlg(param);
break;
case "method":
ThuatToanBiz.callMethod(param);
break;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/*************************************************/
}
}
All the class and calling is valid, I can run this program successfully. But when I try to compile it use CoreCLR, with syntax:
E:\Learning\Viegrid\Native\SVN\trunk\BenchMark\BenchMark>csc /nostdlib /noconfig /r:packages\System.Runtime.4.0.20-beta-22703\lib\contract\System.Runtime.dll /r:packages\System.Console.4.0.0-beta-22703\lib\contract\System.Console.dll /out:runtime\BenchMark.exe Program.cs
Microsoft (R) Visual C# Compiler version 4.6.1055.0 for C# 5 Copyright
(C) Microsoft Corporation. All rights reserved.
I got the error:
Program.cs(13,41): error CS0234: The type or namespace name 'Environment' does not exist in the namespace 'System' (are
you missing an assembly reference?)
Program.cs(18,25): error CS0246: The type or namespace name 'PhepToanDaiSo' could not be found (are you missing a using
directive or an assembly reference?)
Program.cs(18,47): error CS0246: The type or namespace name 'PhepToanDaiSo' could not be found (are you missing a using
directive or an assembly reference?)
Program.cs(22,25): error CS0103: The name 'ThuatToanBiz' does not exist in the current context
I did something wrong? Or coreclr is only can't work with any namespace except "System"?
I have a game developed for iOS as well as android, Here is the code which suddenly started giving an error "Assets/GooglePlayGames/Platforms/PlayGamesClientFactory.cs(31,40): error CS0234: The type or namespace name IOS' does not exist in the namespaceGooglePlayGames'. Are you missing an assembly reference?
"
Here is the code:
using System;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
namespace GooglePlayGames {
internal class PlayGamesClientFactory {
internal static IPlayGamesClient GetPlatformPlayGamesClient() {
if (Application.isEditor) {
return new GooglePlayGames.BasicApi.DummyClient();
}
#if UNITY_ANDROID
return new GooglePlayGames.Android.AndroidClient();
#elif UNITY_IPHONE
return new GooglePlayGames.IOS.IOSClient();
#else
return new GooglePlayGames.BasicApi.DummyClient();
#endif
}
}
}
Error is on the line:
return new GooglePlayGames.IOS.IOSClient();
The use of the platform dependent define "UNITY_IPHONE" is marked as Deprecated.
Unity documentation mentions UNITY_IOS as the new PLatform dependent define for the iOS platform.
http://docs.unity3d.com/Manual/PlatformDependentCompilation.html
The line of GooglePlayGames.IOS.IOSClient(); should be correct. ( not test in my code but the corresponding github archive shows the class in that place.)
Include using GooglePlayGames.IOS; at the top of your file.
I'm using Farseer in my XNA project, but I have some trouble with the ContactListener. I created a class for my ContactListener but I always get these two error messages and I don't know how to fix the problems.
The type or namespace name 'ContactListener' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ContactImpulse' could not be found (are you missing a using directive or an assembly reference?)
What is wrong with my ContactListener class?
class MyContactListener: ContactListener
{
void BeginContact(Contact contact)
{ /* handle begin event */ }
void EndContact(Contact contact)
{ /* handle end event */ }
void PreSolve(Contact contact, ref Manifold oldManifold)
{
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
if (fixtureB.CollisionCategories == Category.Cat10)
{
contact.Enabled = false;
}
}
void PostSolve(Contact contact, ref ContactImpulse impulse)
{ /* handle post-solve event */ }
}
Try this:
Open VS
Go to the Solution Explorer window
Search for a folder called References and right click it
Select Add Reference...
look for the Farseer assembly and add it
And try adding these in code:
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Factories;
using FarseerPhysics.TestBed.Framework;
using Microsoft.Xna.Framework;