Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:13:50+00:00 2026-06-13T19:13:50+00:00

This looks like a bug to me. But, maybe you folks can help me

  • 0

This looks like a bug to me. But, maybe you folks can help me decide.

Is this a bug?

The commented test case is as follows:

using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using Microsoft.CSharp;

namespace CompilerBugTestCase
{
    internal static class Program
    {
        private const string DirectoryName = "TestSourceCode";
        private const string DirectoryNameTrailingSlash = DirectoryName + "/"; // This is intentionally defined with the wrong kind of slash
        private const string FileName = "Test.cs";
        private const string FilePath = DirectoryNameTrailingSlash + FileName; // By composition, this includes the wrong kind of slash

        private static void Main()
        {
            ShowItDoesWorkA();
            Console.WriteLine("ShowItDoesWorkA executed.");

            ShowItDoesWorkB();
            Console.WriteLine("ShowItDoesWorkB executed.");

            ShowItDoesNotWork();
            Console.WriteLine("ShowItDoesNotWork executed.");

            ShowItDoesNotWorkSimple();
            Console.WriteLine("ShowItDoesWorkSimple executed.");

            Console.WriteLine("Press [ ENTER ] to exit");
            Console.ReadLine();
        }

        private static void Setup()
        {
            if (!Directory.Exists(DirectoryName))
            {
                Directory.CreateDirectory(DirectoryName);
            }

            // Notice that this call has no problems
            // It uses the wrong slash, too!
            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            // We're creating a file with the wrong slash here as well.
            File.WriteAllText(FilePath, "using System; namespace TestCode { internal static class TestClass { public static void Main() { Console.WriteLine(\"I work!\"); } } }");
        }

        private static void CompileFiles(string[] files)
        {
            CSharpCodeProvider compiler = new CSharpCodeProvider();
            CompilerParameters parameters = new CompilerParameters()
            {
                GenerateExecutable = false,
                GenerateInMemory = true,
                IncludeDebugInformation = false,
                TreatWarningsAsErrors = true
            };

            CompilerResults results = compiler.CompileAssemblyFromFile(parameters, files);
            if (results.Errors.Count > 0)
            {
                // When looking at this exception, note the path it says it cannot find!
                // You will see it did not translate the path correctly and actually chopped the directory out.
                // Is that really the intended behavior?
                Debug.Fail(results.Errors[0].ErrorText);
            }
        }

        private static void ShowItDoesWorkA()
        {
            Setup();

            string[] files = Directory.GetFiles(DirectoryName);
            CompileFiles(files);
        }

        private static void ShowItDoesWorkB()
        {
            Setup();

            DirectoryInfo directory = new DirectoryInfo(DirectoryName);
            FileInfo[] files = directory.GetFiles();

            string[] paths = new string[files.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                paths[i] = files[i].FullName;
            }

            CompileFiles(paths);
        }

        private static void ShowItDoesNotWork()
        {
            Setup();

            // Here we'll use the path with the wrong kind of slash.
            // It picks up the file just fine.
            string[] files = Directory.GetFiles(DirectoryNameTrailingSlash);
            CompileFiles(files);
        }

        private static void ShowItDoesNotWorkSimple()
        {
            // This is the simplest test case.
            // We hard code the path with the wrong kind of slash and it still crashes.

            Setup();

            string[] files = new string[1] { FilePath };
            CompileFiles(files);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:13:51+00:00Added an answer on June 13, 2026 at 7:13 pm
     private const string DirectoryNameTrailingSlash = DirectoryName + "/";
    

    The path separation character in Windows is a backslash, "\\". Or more accurately, it is Path.DirectorySeparatorChar. Now Windows itself makes some effort to try to interpret a forward slash as a separator as well. That however isn’t always widely matched by other code. Like this snippet I found in the source code for the CodeDOMProvider class:

        internal static bool TryGetProbableCoreAssemblyFilePath(CompilerParameters parameters, out string coreAssemblyFilePath) {
            string multiTargetingPackRoot = null;
            char[] pathSeperators = new char[] { Path.DirectorySeparatorChar };
            // etc..
        }
    

    This kind of code just malfunctions when you use a forward slash. Last but certainly not least, compile options are passed to the compiler with a forward slash. Like /reference.

    Trivially solve your problem by doing this the Right Way: use Path.Combine().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This looks like a long shot, but does anyone know of a way to:
It looks like this question has been asked dozens of times, but none of
** Looks like this was a bug that Facebook has since fixed. I disabled
I want to know what this looks like. I don't have any ideas about
I found this script attached to a modified index page. This looks like some
I'm trying to make the so called fine tune thing. Basically this looks like:
I'm playing with one stack overflow example. This example looks like this: void return_input
It looks like this block directly flushes the output. What's the practical use of
jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
It looks like this template tag works like a charm for most people: http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.