C# 将WPF应用程序复制到其他计算机时System.Windows.Markup.XamlParseException

C# 将WPF应用程序复制到其他计算机时System.Windows.Markup.XamlParseException,c#,wpf,xaml,exception,bitmap,C#,Wpf,Xaml,Exception,Bitmap,我有一个WPF项目,它在我的电脑上运行得很好。但是,当我复制到其他计算机或虚拟机时,它会崩溃,并出现以下错误: System.Windows.Markup.XamlParseException: 'Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception.' Line number '38' and line position '97'. ---> System.Net.WebExcept

我有一个WPF项目,它在我的电脑上运行得很好。但是,当我复制到其他计算机或虚拟机时,它会崩溃,并出现以下错误:

System.Windows.Markup.XamlParseException: 'Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception.' Line number '38' and line position '97'. ---> System.Net.WebException: The device is not ready.
 ---> System.Net.WebException: The device is not ready.
 ---> System.IO.IOException: The device is not ready.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
   at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   --- End of inner exception stack trace ---
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   at System.Net.FileWebRequest.GetResponseCallback(Object state)
   --- End of inner exception stack trace ---
   at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.FileWebRequest.GetResponse()
   at MS.Internal.WpfWebRequestHelper.GetResponse(WebRequest request)
   at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)
   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
   at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
   at System.Windows.Media.Imaging.BitmapImage.EndInit()
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
System.Windows.Markup.XamlParseException:“System.Windows.Media.Imaging.BitmapImage”的初始化引发异常。“行号“38”和行位置“97”。-->System.Net.WebException:设备未就绪。
--->System.Net.WebException:设备未就绪。
--->System.IO.IOException:设备未就绪。
在System.IO.\uuu Error.WinIOError(Int32 errorCode,字符串maybeFullPath)
在System.IO.FileStream.Init(字符串路径、文件模式、文件访问权限、Int32权限、布尔用户权限、文件共享、Int32缓冲大小、文件选项选项、安全属性secAttrs、字符串msgPath、布尔bFromProxy、布尔useLongPath)
位于System.IO.FileStream..ctor(字符串路径、文件模式、文件访问权限、文件共享、Int32 bufferSize、文件选项选项、字符串msgPath、布尔bFromProxy)
位于System.IO.FileStream..ctor(字符串路径、文件模式、文件访问访问、文件共享、Int32 bufferSize、布尔UseAync)
位于System.Net.FileWebStream..ctor(FileWebRequest请求、字符串路径、FileMode模式、FileAccess访问、FileShare共享、Int32长度、布尔异步)
在System.Net.FileWebResponse..ctor(FileWebRequest请求、Uri、FileAccess访问、布尔异步提示)
---内部异常堆栈跟踪的结束---
在System.Net.FileWebResponse..ctor(FileWebRequest请求、Uri、FileAccess访问、布尔异步提示)
位于System.Net.FileWebRequest.GetResponseCallback(对象状态)
---内部异常堆栈跟踪的结束---
位于System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
在System.Net.FileWebRequest.GetResponse()中
在MS.Internal.WpfWebRequestHelper.GetResponse(WebRequest请求)
位于System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri Uri、Stream Stream、BitmapCacheOption、cacheOption、Guid和clsId、Boolean和isOriginalWritable、Stream和uriStream、UnmanagedMemoryStream和UnmanagedMemoryStream、SafeFileHandle和SafeFileHandle)
位于System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri、Uri Uri、Stream、BitmapCreateOptions createOptions、BitmapCacheOption cacheOption、RequestCachePolicy uriCachePolicy、Boolean insertInDecoderCache)
位于System.Windows.Media.Imaging.BitmapImage.FinalizeRecreation()处
位于System.Windows.Media.Imaging.BitmapImage.EndInit()处
位于MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType XamlType、对象obj、布尔begin)
---内部异常堆栈跟踪的结束---
位于System.Windows.Markup.XamlReader.RewrapException(异常e、IXamlLineInfo、Uri baseUri)
在System.Windows.Markup.WpfXamlLoader.Load(XamlReader XamlReader、IXamlObjectWriterFactory writerFactory、Boolean skipJournaledProperties、Object rootObject、XamlObjectWriterSettings设置、Uri baseUri)
位于System.Windows.Markup.wpfxamloader.LoadBaml(XamlReader XamlReader、Boolean skipJournaledProperties、Object rootObject、XamlAccessLevel accessLevel、Uri baseUri)
位于System.Windows.Markup.XamlReader.LoadBaml(Stream-Stream,ParserContext-ParserContext,Object-parent,Boolean-closeStream)
在System.Windows.Application.LoadBamlStreamWithSyncInfo(流,ParserContext pc)
位于System.Windows.Application.LoadComponent(Uri resourceLocator,布尔bSkipJournaledProperties)
在System.Windows.Application.DoStartup()中
在System.Windows.Application.b__1(未使用的对象)
位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs)
位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源、委托方法、对象参数、Int32 numArgs、委托catchHandler)
图像作为全局资源嵌入到项目文件中

有什么建议会导致这种情况吗

更新:我已将问题本地化: 当我使用以下代码时

    <Image Margin="148,80,144,114">
        <Image.Source>
            <ImageSource>hexagon4.png</ImageSource>
        </Image.Source>
    </Image>

hexagon4.png
应用程序传输良好

当我使用

<Image Margin="148,80,144,114" Source="{DynamicResource myimage}"/>

应用程序在传输后崩溃


下面是重现错误的项目:

您的代码中没有使用绝对路径吗?您能给我们看一下这些图像的代码吗?我添加了一些代码来说明问题以及如何设置资源?在Expression Blend Source->Convert to new resource->entered key name and place中。我选择的每个存储位置的应用程序都会崩溃我认为您混淆了两种类型的资源:XAML资源(什么
DynamicResource
reads)与.Net资源(我认为Blend产生的)不同。