2015-06-27 18 views
6

Wyobrażam sobie, że dzieje się coś głupiego, ponieważ pozostałe atrybuty poziomu zespołu mogą być włączone, ale gdy zostanie zadeklarowane AssemblyCopywriteAttribute lub AssemblyCompanyAttribute, spowoduje to błędy CS0116 i CS1730. Biorąc pod uwagę, że kod nie zawiera żadnych deklaracji metod, nie widzę, w jaki sposób można zastosować CS0116 i nie ma rozproszonych definicji typów, więc nie jestem pewien, w jaki sposób można zastosować.Błąd kompilacji podczas korzystania z AssemblyCopyrightAttribute lub AssemblyCompanyAttribute przez CodeDomProvider

Błędy

Error Number: CS0116 
Error Text: A namespace cannot directly contain members such as fields or methods 

Error Number: CS1730 
Error Text: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations 

Plik źródłowy:

using System; 
using System.Reflection; 
using System.Runtime.InteropServices; 

[assembly: ComVisible(false)] 
[assembly: CLSCompliant(false)] 
[assembly: AssemblyCompany("My Company")]; // this results in a compile time error 
[assembly: Guid("9d8271d9-957f-46dc-bcc6-1055137b4fad")] 
[assembly: AssemblyTitle("CCDA MAP")] 
[assembly: AssemblyDescription("The mapping logic to source a CXD and populate a CCDA")] 
[assembly: AssemblyCopyright("My Company 2015")]; // this results in a compile time error 
[assembly: AssemblyCulture("en-US")] 
[assembly: AssemblyVersion("2.2.0")] 
[assembly: AssemblyFileVersion("2.2.0.123")] 
[assembly: AssemblyConfiguration("DEBUG")] 
[assembly: AssemblyMetadataAttribute("Built","06/27/2015")] 
[assembly: AssemblyMetadataAttribute("Host","JORMUNGANDR")] 
[assembly: AssemblyMetadataAttribute("The answer","42")] 
[assembly: AssemblyMetadataAttribute("Document Type","CCDA")] 
[assembly: AssemblyMetadataAttribute("Document Spec Version","2.0")] 

Kompilacja Logic

CodeDomProvider provider = CodeDomProvider.CreateProvider("C#"); 
var source = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"codedom"),"*.cs").ToList().Dump("Map Source").Select(i=>File.ReadAllText(i)).ToArray(); 
var parameters = new CompilerParameters{ GenerateInMemory = true, OutputAssembly = string.Format("Map.dll",count),TreatWarningsAsErrors = true, WarningLevel = 4}; 
parameters.ReferencedAssemblies.Add("mscorlib.dll"); 
var results = provider.CompileAssemblyFromSource(parameters, source); 

Odpowiedz

7

błąd jest c aused błędnymi średnikami w tekście:

[assembly: AssemblyCopyright("My Company 2015")]; // this results in a compile time error 

Powinno być:

[assembly: AssemblyCopyright("My Company 2015")] // this does not result in a compile time error 

I:

[assembly: AssemblyCompany("My Company")]; // this results in a compile time error 

Powinno być:

[assembly: AssemblyCompany("My Company")] // this does not result in a compile time error 

Usunięcie ich kasuje się błędy widzisz.

Powiązane problemy