相关疑难解决方法(0)

System.Random构造函数中的错误?

这个System.Threading.ConcurrentQueue.TryDequeue方法在前几天引发了一个例外,让我完全惊讶.这是堆栈跟踪:

System.OverflowException: Negating the minimum value of a twos complement number is invalid.
   at System.Math.AbsHelper(Int32 value)
   at System.Random..ctor(Int32 Seed)
   at System.Threading.Collections.ConcurrentQueue`1.TryDequeueCore(T& result)
   at System.Threading.Collections.ConcurrentQueue`1.TryDequeue(T& result)
   at MyProgram.ThreadProc() in c:\MyProgram\Main.cs:line 118
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
Run Code Online (Sandbox Code Playgroud)

起初我认为问题是TryDequeueCore调用Random具有错误值的构造函数.但进一步调查显示TryDequeueCore调用默认构造函数.它看起来像错误是在Random构造函数中:

.method public hidebysig specialname rtspecialname 
        instance void  .ctor() cil managed
{
  // Code size       12 (0xc)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  call       int32 System.Environment::get_TickCount()
  IL_0006:  call       instance void System.Random::.ctor(int32)
  IL_000b: …
Run Code Online (Sandbox Code Playgroud)

.net c#

20
推荐指数
1
解决办法
831
查看次数

Uri.TryCreate抛出UriFormatException?

我有一个方法,尝试创建一个Uri,然后清理它(删除片段,排除一些域和查询字符串模式等).该方法如下所示:

static public bool TryCreateCleanUri(Uri baseUri, string relstr, out Uri result)
{
    if (!Uri.TryCreate(baseUri, relstr, out result))
    {
        return false;
    }
    return CleanupUri(result, out result);
}
Run Code Online (Sandbox Code Playgroud)

这种方法已经好几个月了.但是昨晚失败了.Uri.TryCreate()抛出异常!这是堆栈跟踪:

ERROR: Unhandled exception caught.  Program terminating.
System.UriFormatException: Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, Flags& flags, String& scopeId)
   at System.Uri.CreateHostString()
   at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
   at System.Uri.CombineUri(Uri basePart, String relativePart, UriFormat uriFormat)
   at System.Uri.GetCombinedString(Uri baseUri, String relativeStr, Boolean dontEscape, String& result)
   at System.Uri.ResolveHelper(Uri baseUri, Uri …
Run Code Online (Sandbox Code Playgroud)

.net c#

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×2

c# ×2