如何解决targetinvocationexception? [英] How to solve targetinvocationexception?

查看:133
本文介绍了如何解决targetinvocationexception?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抛出'System.Reflection.TargetInvocationException'。我不明白为什么innerException会告诉IsolatedStorage,因为我在sdCard中创建了该文件夹。



 _ className   System.Reflection.TargetInvocationException 
_innerException {System.IO.IsolatedStorage.IsolatedStorageException:IsolatedStorageFileStream上不允许操作。
在System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor( String 路径,FileMode模式,FileAccess访问,FileShare共享, Int32 bufferSize,IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor( String path,FileMode mode,IsolatedStorageFile isf )
在MarketApp.ShortTimeStoring。< FillPricesFromIsoStore> d__0.MoveNext()
---堆栈跟踪结束来自之前的位置抛出异常---
在System.Runtime.CompilerServices.AsyncMethodBuilderCore。< ThrowAsync> b__3( Object state)}
_message 调用目标抛出了异常。
IsTransient false
来源< span class =code-string> mscorlib





我的尝试:



这是我的代码:

 StorageFolder myFolder =  await  KnownFolders.PicturesLibrary.CreateFolderAsync(  MarketApp,CreationCollisionOption.ReplaceExisting); 
StorageFile myFile = await myFolder.CreateFileAsync( Products.txt,CreationCollisionOption.ReplaceExisting);
流f = 等待 myFile.OpenStreamForWriteAsync();
使用(StreamWriter sw = new StreamWriter(f))
{
sw.WriteLine( Hello world!);
}

解决方案

代码中的某处出现严重错误。但找到根本原因的唯一方法是使用调试器逐步执行代码并确切检查发生了什么。


我找到了InnerException的位置,我发现问题出在其他地方

'System.Reflection.TargetInvocationException' is thrown. I don't understand why the innerException tells something about IsolatedStorage because I create that folder in sdCard.

_className	"System.Reflection.TargetInvocationException"
_innerException	{System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, IsolatedStorageFile isf)
   at MarketApp.ShortTimeStoring.<FillPricesFromIsoStore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)}
_message	"Exception has been thrown by the target of an invocation."
IsTransient	false
Source	"mscorlib"



What I have tried:

This is my code:

StorageFolder myFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MarketApp", CreationCollisionOption.ReplaceExisting);
StorageFile myFile = await myFolder.CreateFileAsync("Products.txt", CreationCollisionOption.ReplaceExisting);
Stream f = await myFile.OpenStreamForWriteAsync();
using (StreamWriter sw = new StreamWriter(f))
{
    sw.WriteLine("Hello world!");
}

解决方案

There is something seriously wrong, somewhere in your code. But the only way to find the root cause is to step through the code with your debugger and check exactly what is happening.


I found the place for InnerException and I found out that problem was elsewhere.


这篇关于如何解决targetinvocationexception?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆