errors CS0246 and CS1504 when trying to compile through csc RRS feed

  • Question

  • Hi!

    I am completely new to c#. I have created a small script, which I can execute in Visual Studio, but which I cannot compile from terminal. Here is my code:

    using System;
    using System.IO;
    using System.Net;
    using System.Text;
    using Newtonsoft.Json.Linq;
    namespace Examples.System.Net
        public class WebRequestGetExample
            public static void Main()
                //Create request
                WebRequest request = WebRequest.Create(
                // Set the credentials  
                request.Credentials = new NetworkCredential("username", "password");
                request.PreAuthenticate = true;
                // Get the response  
                WebResponse response = request.GetResponse();
                // //capture json response as a string named json
                using (Stream responseStream = response.GetResponseStream())
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    string json = reader.ReadToEnd();
                    //Parse json
                    JObject jo = JObject.Parse(json);
                    //Extract attachment
                    string excel_64 = (string)jo["attachment"];
                    //Remove unnecessary string snippet
                    string replacedString = excel_64.Replace("data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,", "");
                    //Decode from base64 to bytes
                    byte[] textAsBytes = Convert.FromBase64String(replacedString);
                    //Create binary writer
                    BinaryWriter bw = new BinaryWriter(new FileStream("/path/to/my/excel_file", FileMode.Create));
                    //Write to file

    I can execute it correctly in Visual Studio, but when I run:

    csc Program.cs

    I get:

    Program.cs(5,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using
            directive or an assembly reference?)

    I  have downloaded the file Newtonsoft.Json.dll to the same folder where Program.cs is, and when I run:

    csc ./reference:Newtonsoft.Json.dll Program.cs

    I get:

    error CS1504: Source file 'C:\Users\jramirezle001\source\repos\ConsoleApp1\ConsoleApp1\./reference:Newtonsoft.Json.dll' could not be opened -- The given path's format is not supported.

    Further, if I run:

    csc Newtonsoft.Json.dll Program.cs

    I get:

    error CS2015: 'C:\Users\jramirezle001\source\repos\ConsoleApp1\ConsoleApp1\Newtonsoft.Json.dll' is a binary file instead of a text file

    So, I am completely lost. Any help would be much appreciated! Thank you in advance!

    Monday, December 10, 2018 4:09 PM

All replies

  • Try the “-reference” option:

      csc Program.cs -reference:Newtonsoft.Json.dll


    Monday, December 10, 2018 6:28 PM
  • Hi friend,

    Welcome to the MSDN forum.

    It seems your issue is about the C# development and our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum for a better support, thank you for your understanding.

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, December 11, 2018 6:45 AM
  • You put a dot in front of the /reference parameter.

    csc /reference:Newtonsoft.json.dll Program.cs

    You can build your code in VS and then look at the build log to get the command that VS is running. It generally needs more references than just what you're providing.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, December 11, 2018 3:40 PM