我正在尝试在我的Silverlight for Windows Phone 7应用程序中播放音频.我有一个MP3音频文件,其构建操作设置为资源.要播放声音,我使用:
SoundEffectInstance sfi = null;
...
Stream source = Application.GetResourceStream(new Uri("/Bird Calls;component/Crow.mp3", UriKind.Relative)).Stream;
Microsoft.Xna.Framework.Audio.SoundEffect effect = SoundEffect.FromStream(source);
sfi = effect.CreateInstance();
sfi.Play();
Run Code Online (Sandbox Code Playgroud)
此代码在SoundEffect.FromStream方法中抛出InvalidOperationException.
c# audio invalidoperationexception windows-phone-7 soundeffect
我正在使用Razor在VS2013中使用VB.NET MVC 5.1
siq.Price是一个十进制?
我正在尝试检查siq.Price是否有值,如果是,则将其打印为货币.我在尝试访问.Value属性时收到此错误,其中true为.HasValue返回true的元素:
可以为空的对象必须具有值.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.InvalidOperationException:Nullable对象必须具有值.
我尝试了这两行代码,认为它们应该没有问题,但收到了上面的错误:
@IIf(siq.Price.HasValue, siq.Price.Value, "N/A")
'and
@IIf(siq.Price.HasValue, siq.Price.Value.ToString("C"), "N/A")
Run Code Online (Sandbox Code Playgroud)
一旦我从TruePart中删除了.Value,它就开始工作了:
@IIf(siq.Price.HasValue, siq.Price, "N/A")
'and
@IIf(siq.Price.HasValue, String.Format("{0:C}", siq.Price), "N/A")
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么会这样吗?!我很困惑.
注意:如果Price有值,这段代码就可以自己运行,但是在IIf()中没有:
@siq.Price.Value.ToString("C")
Run Code Online (Sandbox Code Playgroud) 以下是代码段:
class xxx
{
public xxx(){}
try
{
throw new Exception(InvalidoperationException);
}
catch(Exception x)
{
}
catch(InvalidoperationException x)
{
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉这里会引发哪个例外,背后的原因是什么.
.net c# exception-handling exception invalidoperationexception
我用c#编程.我正在尝试从a中删除一个项目,List<>但是当我删除该项目时,我收到此异常错误:
mscorlib.dll中出现"System.InvalidOperationException"类型的异常,但未在用户代码中处理
附加信息:收集已修改; 枚举操作可能无法执行.
这是我的代码:
foreach (Target t in targetList)
{
if (t.CalculateDistance(t.EndX, t.EndY) <= 5)
{
targetList.Remove(t);
}
}
Run Code Online (Sandbox Code Playgroud)
我在第一行得到例外.为什么我看到这个错误?或者我该如何解决?
我正在尝试按商品名称查找商品。
Item item = Shop.Items.Values.First(i => i.Name.Contains(partOfName))
Run Code Online (Sandbox Code Playgroud)
我希望下一步
if (item == null) // if not found
{
// not found code
}
Run Code Online (Sandbox Code Playgroud)
...但是当找不到物品时,我得到了InvalidOperationException。
首先想到的是
try
{
Item item = Shop.Items.Values.First(i => i.Name.Contains(partOfName))
}
catch(InvalidOperationException ex)
{
// not found code
}
Run Code Online (Sandbox Code Playgroud)
最好的处理方法是什么?也许没有try / catch?
编辑。 解:
Item item = Shop.Items.Values.FirstOrDefault(i => i.Name.Contains(partOfName))
if (item == null) // if not found
{
// not found code
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试向SQL Server插入供应商,但它总是在该行上引发异常cmd.ExecuteNonQuery().真的需要一些帮助!

c# ×5
.net ×1
asp.net-mvc ×1
audio ×1
exception ×1
linq ×1
list ×1
nullable ×1
razor ×1
soundeffect ×1
sql-server ×1
sqlexception ×1
vb.net ×1