NullReferenceException в Microsoft.Silverlight.Build.Tasks.CompileXaml.LoadAssemblies (ITaskItem [] ReferenceAssemblies) - PullRequest
0 голосов
/ 12 мая 2010

Я обновил Visual Studio 2010 до версии 10.0.30319.1 RTM Rel и начал получать следующее исключение во время сборки:

System.NullReferenceException: ссылка на объект не установлена ​​для экземпляра объекта. в Microsoft.Silverlight.Build.Tasks.CompileXaml.LoadAssemblies (ITaskItem [] ReferenceAssemblies) в Microsoft.Silverlight.Build.Tasks.CompileXaml.get_GetXamlSchemaContext () в Microsoft.Silverlight.Build.Tasks.CompileXaml.GenerateCode (элемент ITaskItem, Boolean isApplication) в Microsoft.Silverlight.Build.Tasks.CompileXaml.Execute () в Bohr.Silverlight.BuildTasks.BohrCompileXaml.Execute ()

Код BohrCompileXaml.Execute следующий:

     public override bool Execute() {
        List<TaskItem> pages = new List<TaskItem>();
        foreach (ITaskItem item in SilverlightPages) {
            string newFileName = getGeneratedName(item.ItemSpec);
            String content = File.ReadAllText(item.ItemSpec);
            String parentClassName = getParentClassName(content);
            if (null != parentClassName) {
                content = content.Replace("<UserControl", "<" + parentClassName);
                content = content.Replace("</UserControl>", "</" + parentClassName + ">");
                content = content.Replace("bohr:ParentClass=\"" + parentClassName + "\"", "");
            }
            File.WriteAllText(newFileName, content);
            pages.Add(new TaskItem(newFileName));
        }

        if (null != SilverlightApplications) {
            foreach (ITaskItem item in SilverlightApplications) {
                Log.LogMessage(MessageImportance.High, "Application: " + item.ToString());
            }
        }

        foreach (ITaskItem item in pages) {
            Log.LogMessage(MessageImportance.High, "newPage: " + item.ToString());
        }


        CompileXaml xamlCompiler = new CompileXaml();
        xamlCompiler.AssemblyName = AssemblyName;
        xamlCompiler.Language = Language;
        xamlCompiler.LanguageSourceExtension = LanguageSourceExtension;
        xamlCompiler.OutputPath = OutputPath;
        xamlCompiler.ProjectPath = ProjectPath;
        xamlCompiler.RootNamespace = RootNamespace;
        xamlCompiler.SilverlightApplications = SilverlightApplications;
        xamlCompiler.SilverlightPages = pages.ToArray();
        xamlCompiler.TargetFrameworkDirectory = TargetFrameworkDirectory;
        xamlCompiler.TargetFrameworkSDKDirectory = TargetFrameworkSDKDirectory;
        xamlCompiler.BuildEngine = BuildEngine;
        bool result = xamlCompiler.Execute(); // HERE we got the error!  

И определение задачи:

        <BohrCompileXaml 
           LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
           Language="$(Language)" 
           SilverlightPages="@(Page)" 
           SilverlightApplications="@(ApplicationDefinition)" 
           ProjectPath="$(MSBuildProjectFullPath)"
           RootNamespace="$(RootNamespace)"
           AssemblyName="$(AssemblyName)" 
           OutputPath="$(IntermediateOutputPath)"
           TargetFrameworkDirectory="$(TargetFrameworkDirectory)" 
           TargetFrameworkSDKDirectory="$(TargetFrameworkSDKDirectory)"
           >

        <Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />

        <!-- Add to the list list of files written. It is used in Microsoft.Common.Targets to clean up 
             for a next clean build 
          -->
        <Output ItemName="FileWrites" TaskParameter="WrittenFiles" />
        <Output ItemName="_GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />

    </BohrCompileXaml>

В чем может быть причина? И как я могу получить больше информации о том, что происходит внутри класса CompileXaml?

1 Ответ

0 голосов
/ 12 мая 2010

Мое первое предположение состоит в том, что параметр ReferenceAssemblies равен нулю. ReferenceAssemblies используется для получения XamlSchemaContext в CompileTask.

Чтобы это работало, у вас есть два варианта:

  • Установите для свойства SkipLoadingAssembliesInXamlCompiler значение true
  • Или передать путь сборки в ReferenceAssemblies свойстве ( mscorlib.dll или другой dll silverlight)

Проще установить свойство SkipLoadingAssembliesInXamlCompiler в true. Для этого измените вашу задачу BohrCompileXaml следующим образом:

CompileXaml xamlCompiler = new CompileXaml();
...
xamlCompiler.SkipLoadingAssembliesInXamlCompiler = true;
...