Skip to content

Version1.3.2:caused a CompilationErrorException error error CS0234: The type or namespace name 'Thunk' does not exist in the namespace 'System.EnterpriseServices' (are you missing an assembly reference?) #29433

@Chickenbrother

Description

@Chickenbrother

Version1.3.2:

Code:

                var references = new List<Assembly>();
                var imports = new List<string>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())

                {
                    if (assembly.FullName.Contains("mscorlib"))
                    {
                        continue;
                    }
                    if (assembly.IsDynamic)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(assembly.Location))
                    {
                        continue;
                    }

                    references.Add(assembly);
                    try
                    {
                        var namepsaces = assembly.GetTypes()
                        .Where(t => string.IsNullOrWhiteSpace(t.Namespace) == false)
                        .Select(t => t.Namespace);
                        foreach (string item in namepsaces.Distinct())
                        {
                            imports.Add(item);
                        }

                    }
                    catch (System.Reflection.ReflectionTypeLoadException reflx)
                    {
                        Console.WriteLine($"Skipping assembly {assembly.FullName}. Err: {reflx}");
                    }
                }
                references = references.Distinct().ToList();
                imports = imports.Distinct().ToList();
                #endregion
                

                var options =
                   ScriptOptions.Default.AddImports(imports)
                   .AddReferences(references);
                //var path = System.Reflection.Assembly.GetAssembly(typeof(System.Data.DataTableExtensions)).Location;
                //var asm = Microsoft.CodeAnalysis.AssemblyMetadata.CreateFromFile(path).GetReference();
                //var options =
                //   ScriptOptions.Default.WithImports("System", "System.Data", "System.Linq")
                //   .AddReferences(asm)
                //   .AddReferences(references)
                //   .AddReferences((typeof(System.Linq.Enumerable).Assembly))
                //   .AddReferences((typeof(System.Data.DataSet).Assembly)).AddReferences((typeof(System.Data.DataTable).Assembly));
                var globals = new Globals() { };
                try
                {
                    scriptState = scriptState == null ? CSharpScript.RunAsync(code, options: options, globals: globals).Result : scriptState.ContinueWithAsync(code, options: options).Result;
                    if (scriptState.ReturnValue != null)
                        return scriptState.ReturnValue;
                    return null;
                }
                catch (CompilationErrorException error)
                {
                    Console.WriteLine(error.ToString());
                    ; return null;
                }
  1. code segment ,when i run it , caused a CompilationErrorException error
    error CS0234: The type or namespace name 'Thunk' does not exist in the namespace 'System.EnterpriseServices' (are you missing an assembly reference?)
  2. i add reference
    image
    it doesn't work
    3.i use references.Add(Assembly.Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")); it doesn't work .

question:
Can anyone help me with this problem?

Expected Behavior:

Actual Behavior:

Metadata

Metadata

Assignees

Labels

Area-InteractiveConcept-APIThis issue involves adding, removing, clarification, or modification of an API.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions