Silverlight给我一个错误,说明.dll文件没有启用?

时间:2014-04-03 21:46:56

标签: silverlight

我正在尝试编写一个简单的Silverlight应用程序,它上面有几个按钮,但我一直收到这个错误。我已经离开文件资源管理器以查看有关更改文件权限的信息,以便MS Studio可以找到它,但到目前为止还没有发现任何变化。

问题:在Visual Studio for Silverlight中是否需要更改某些内容才能正常工作?

Silverlight 4是我对WEBApplication的目标。

我不确定需要在这个问题上添加什么才能让每个人都知道我在问什么。我认为它只是一个来自MS的文件,必须启用,这是SilverlightApplication3.dll,但我没有真正的运气启用它。

错误:

Error   1   Could not load the assembly file:///C:\Users\itpr13266\Desktop\C++\SilverlightApplication3\SilverlightApplication3\obj\Debug\SilverlightApplication3.dll. This assembly may have been downloaded from the Web.  If an assembly has been downloaded from the Web, it is flagged by Windows as being a Web file, even if it resides on the local computer. This may prevent it from being used in your project. You can change this designation by changing the file properties. Only unblock assemblies that you trust. See http://go.microsoft.com/fwlink/?LinkId=179545 for more information.  

XML:

<UserControl x:Class="SilverlightApplication3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="28,64,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="28,93,0,0" Name="button2" VerticalAlignment="Top" Width="75" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="28,122,0,0" Name="button3" VerticalAlignment="Top" Width="75" />
        <Image Height="124" HorizontalAlignment="Left" Margin="31,156,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="332" />
        <Border BorderBrush="Silver" BorderThickness="1" Height="120" HorizontalAlignment="Left" Margin="113,24,0,0" Name="border1" VerticalAlignment="Top" Width="251">
            <TextBox Height="102" Name="textBox1" Width="221" />
        </Border>
    </Grid>
</UserControl>

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication3
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
}

代码:

using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication3
{
    public partial class App : Application
    {

        public App()
        {
            this.Startup += this.Application_Startup;
            this.Exit += this.Application_Exit;
            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();
        }

        private void Application_Exit(object sender, EventArgs e)
        {

        }

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // the browser's exception mechanism. On IE this will display it a yellow alert 
            // icon in the status bar and Firefox will display a script error.
            if (!System.Diagnostics.Debugger.IsAttached)
            {

                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled. 
                // For production applications this error handling should be replaced with something that will 
                // report the error to the website and stop the application.
                e.Handled = true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
            }
        }

        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
        {
            try
            {
                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
            }
            catch (Exception)
            {
            }
        }

0 个答案:

没有答案