Exemple #1
0
        public void BadPdb_DotInAlias()
        {
            var source  = @"
public class C
{
    public static void Main()
    {
    }
}
";
            var comp    = CreateCompilation(source);
            var peImage = comp.EmitToArray();

            var symReader = ExpressionCompilerTestHelpers.ConstructSymReaderWithImports(
                peImage,
                "Main",
                "USystem",                                                                                                                  // Valid.
                "AMy.Alias TSystem.Globalization.CultureInfo, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", // Invalid - skipped.
                "ASI USystem.IO");                                                                                                          // Valid.

            var module      = ModuleInstance.Create(peImage, symReader);
            var runtime     = CreateRuntimeInstance(module, new[] { MscorlibRef });
            var evalContext = CreateMethodContext(runtime, "C.Main");
            var compContext = evalContext.CreateCompilationContext(); // Used to throw.
            var imports     = compContext.NamespaceBinder.ImportChain.Single();

            Assert.Equal("System", imports.Usings.Single().NamespaceOrType.ToTestDisplayString());
            Assert.Equal("SI", imports.UsingAliases.Keys.Single());
            Assert.Equal(0, imports.ExternAliases.Length);
        }
Exemple #2
0
        public void BadPdb_DotInAlias()
        {
            var source = @"
public class C
{
    public static void Main()
    {
    }
}
";
            var comp   = CreateCompilationWithMscorlib(source);

            byte[] exeBytes;
            byte[] unusedPdbBytes;
            ImmutableArray <MetadataReference> references;
            var result = comp.EmitAndGetReferences(out exeBytes, out unusedPdbBytes, out references);

            Assert.True(result);

            var symReader = ExpressionCompilerTestHelpers.ConstructSymReaderWithImports(
                exeBytes,
                "Main",
                "USystem",                                                                                                                  // Valid.
                "AMy.Alias TSystem.Globalization.CultureInfo, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", // Invalid - skipped.
                "ASI USystem.IO");                                                                                                          // Valid.

            var runtime     = CreateRuntimeInstance("assemblyName", references, exeBytes, symReader);
            var evalContext = CreateMethodContext(runtime, "C.Main");
            var compContext = evalContext.CreateCompilationContext(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)); // Used to throw.
            var imports     = compContext.NamespaceBinder.ImportChain.Single();

            Assert.Equal("System", imports.Usings.Single().NamespaceOrType.ToTestDisplayString());
            Assert.Equal("SI", imports.UsingAliases.Keys.Single());
            Assert.Equal(0, imports.ExternAliases.Length);
        }