【问题标题】:Building XAML file in visual Studio results in an error on a line that does not exist在 Visual Studio 中构建 XAML 文件会导致不存在的行出现错误
【发布时间】:2018-09-29 21:06:42
【问题描述】:

请查看我的 .xaml 文件中的完整代码。如您所见,它只有 10 行:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage BackgroundColor="Black"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ImageTest"             
             x:Class="ImageTest.ImagePage">

    <Button Image="clock.png" x:Name="btn" />

</ContentPage>

当我尝试构建我的项目时,我收到以下错误消息:

Severity    Code    Description Project File    Line    Suppression State
Error       Position 12:16. 
Type EmbeddedImage not found in xmlns http://xamarin.com/schemas/2014/forms ImageTest

D:\Mobile Apps\Mosh\ImageTest\ImageTest\ImageTest\ImagePage.xaml    12  

为什么 Visual Studio 在不存在的行上给我一个错误?

【问题讨论】:

    标签: c# xamarin visual-studio-2017


    【解决方案1】:

    这是因为您的 XAML 文件在构建时被编译为 .g.cs 文件。执行时,此编译文件会引发错误,因此 Visual Studio 会显示已编译文件的错误,并且行号将不适用。

    如果您更改了文件,您应该清理构建/重建您的解决方案,以删除旧的编译文件。 (Error in a .g.cs file?)

    【讨论】:

    • 太好了,解决了这个问题,非常感谢!我的下一个问题是一个新错误:“ResolveLibraryProjectImports”任务意外失败。 System.IO.FileNotFoundException:无法加载程序集“ImageTest,版本=0.0.0.0,文化=中性,PublicKeyToken=”。也许它在 Mono for Android 配置文件中不存在?文件名:'ImageTest.dll'。让我们看看如何解决这个问题:)
    猜你喜欢
    • 2020-03-15
    • 2016-07-08
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    相关资源
    最近更新 更多