Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Microsoft.Silverlight.Build.Tasks.CompileXML.LoadAssembly(ITaskItem[]ReferenceAssembly)上的NullReferenceException_Silverlight_Msbuild_Msbuild Task - Fatal编程技术网

Microsoft.Silverlight.Build.Tasks.CompileXML.LoadAssembly(ITaskItem[]ReferenceAssembly)上的NullReferenceException

Microsoft.Silverlight.Build.Tasks.CompileXML.LoadAssembly(ITaskItem[]ReferenceAssembly)上的NullReferenceException,silverlight,msbuild,msbuild-task,Silverlight,Msbuild,Msbuild Task,我将Visual Studio 2010更新为版本10.0.30319.1 RTM Rel,并在生成过程中开始出现以下异常: System.NullReferenceException:对象引用未设置为对象的实例。 位于Microsoft.Silverlight.Build.Tasks.CompileXML.LoadAssembliesITaskItem[]ReferenceAssembly 在Microsoft.Silverlight.Build.Tasks.CompileXaml.get_G

我将Visual Studio 2010更新为版本10.0.30319.1 RTM Rel,并在生成过程中开始出现以下异常:

System.NullReferenceException:对象引用未设置为对象的实例。 位于Microsoft.Silverlight.Build.Tasks.CompileXML.LoadAssembliesITaskItem[]ReferenceAssembly 在Microsoft.Silverlight.Build.Tasks.CompileXaml.get_GetXamlSchemaContext上 在Microsoft.Silverlight.Build.Tasks.CompileXML.GenerateCodeITaskItem项中,布尔值为应用程序 在Microsoft.Silverlight.Build.Tasks.CompileXML.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>

原因可能是什么?如何获得CompileXML类中发生的更多信息?

我的第一个猜测是参数referenceAssembly为null。ReferenceAssembly用于获取CompileTask中的XamlSchemaContext

要使其发挥作用,您有两种选择:

将属性skiploadinadingassembliesinxamlcompiler设置为true 或者在ReferenceAssembles属性mscorlib.dll或其他silverlight dll中传递程序集路径 更简单的方法是将属性SkipLoadingAssembliesInXamlCompiler设置为true。为此,请修改BohrCompileXaml任务,如下所示:

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

对不起,我对这些东西都不熟悉,所以请你说清楚一点。如何设置这些属性?添加了代码。我不知道BohrCompileXaml是什么,但你必须修改它。你使用的是Microsoft.Silverlight.Build.Tasks的哪个版本?是的,你是对的,刚刚注意到我们使用了svn的dll,所以我用新的替换了它。仍然需要skiploadinadingassembliesinxamlcompiler选项才能使其工作。所以你完全正确。谢谢