On Fri, 11 Apr 2008 08:52:53 -0700, Rinaldo
<zw*************@hotmail.com.nospamwrote:
How small it must be?
It must be no larger than the absolute minimum required to reproduce the
problem. It must be no smaller than the minimum amount of code that can
be compiled without adding anything.
The original code you posted isn't complete (nor the latest, which is the
same). It uses variables that aren't declared and for which we have no
way of knowing their values. The "whole code" you posted isn't even close
to being concise. It is literally the whole code, which isn't what I
asked for. "Complete" simply means that I don't have to add anything. It
doesn't mean that I need every line of code you've written.
Here's a concise-but-complete code example that _doesn't_ reproduce the
problem:
using System;
using System.Collections.Generic;
using System.Text;
namespace TestCreateUri
{
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("ftp://ftp.lampiesoft.nl");
Console.WriteLine("Uri: " + uri.ToString());
Console.ReadLine();
}
}
}
You claimed that there's a problem creating the Uri. You create the Uri
using a string, so it should be possible to post code that simply passes
some string literal to the constructor and throws the exception.
In my example, I used the only full URL you offered as my test string. It
runs just fine, so obviously that string isn't the one throwing the
exception.
Hopefully, you can provide something similar to the above but with a
string that does throw an exception. Then someone here (maybe even me)
can explain why the string's not valid.
It's _possible_ that you may need to provide more elaborate code. In that
case, that would mean that there's something other than just the string
causing the problem. That the string itself is normally valid, but that
something else in your code is somehow causing it to be invalid.
Hopefully that's won't be the case; if it is, it is likely to take a lot
more effort on your part to come up with an example. However, if it is
the case, then the only way for you to get help is to provide that
example. No one here gets paid enough to sift through your complete
application code to try to find the magic combination that causes the
error.
So, as a first step: try to provide the very simplest example. What's the
string being passed to the constructor when the exception is thrown? Does
passing that string to the constructor cause the exception even in the
context of a program as simple as what I showed above? If so, write a
version of the code above using that string, so that we can see what the
actual string is.
If not, then you need to figure out how to make a program that contains
the very minimum amount of code that will still reproduce the problem.
The most direct way to do that is to create a copy of your existing
project and start removing things until the problem goes away. Start with
the things that seem the least necessary.
As I said, the exercise itself may lead you to the problem and you won't
need anyone else to point it out. But at the very least, when you're done
you'll have a nice, simple example that you can post here.
Pete