.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

URI constructor help with canonicalization

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :.NET Framework


I have the following url: http://hi.baidu.com/%B1%F9%BA%F8%C7%EF%D4%C2 

when I use the new Uri constructor on it, it "compact the url" to a format that is not valid, I looked into the URI documentation and I found the following paragraph:

"As part of canonicalization in the constructor for some schemes, escaped representations are compacted. The schemes for which URI will compact escaped sequences include the following: file, http, https, net.pipe, and net.tcp. For all other schemes, escaped sequences are not compacted. For example: if you percent encode the two dots ".." as "%2E%2E" then the URI constructor will compact this sequence for some schemes. For example, the following code sample shows a URI constructor for the http scheme."

so it does alter the url if it has http schema, but does not touch it when it's ftp. Is there a way to force new URI constructor to not touch the url? 

I have to assign a uri object and this is screwing up the input url!


View Complete Post

More Related Resource Links

default constructor SelectList




dont have a  default constructor

new SelectList() :(


Any realtime example for constructor...???

Referenced WebService, class constructor with parameters

Hi, I have WebService which is referenced in C# ClassLibrary project. In WebService project I have a class named User, which has two constructors - one without parameters and one whith parameters. When I try to create instance of User class from WS in ClassLibrary, I can use only constructor with parameters. My question is, how can I use in constructor with parameters like User u = new User("some@email.com", ...);. Any idea? Thansk

System.Uri constructor. Bug or my misunderstanding?

Hello. I use this Uri constructor: Uri (Uri, String). Base uri refers to: https://admin.fedoraproject.org/updates/F13/security?_csrf_token=bfd822860e8c532850b9ba817aebecbefdd490be and ?updates_tgp_no=2&_csrf_token=e075a5525532054a2e0f58c4674f875a6779b37a&updates_tgp_limit=25 stands for the relative address. What should be the target uri? I believe it is : https://admin.fedoraproject.org/updates/F13/security?updates_tgp_no=2&_csrf_token=e075a5525532054a2e0f58c4674f875a6779b37a&updates_tgp_limit=25 but I get https://admin.fedoraproject.org/updates/F13/?updates_tgp_no=2&_csrf_token=e075a5525532054a2e0f58c4674f875a6779b37a&updates_tgp_limit=25 so 'security' is omitted. Can anybody tell me why it's so?

Custom Authenticate Attribute with Constructor (Dependency) Injection

  I have a [BeastAuthenticate] attribute on my controller.  The following code works fine but I would like to use Contructor (Dependency) Injection with Unity.  The problem is that the attribute will run the contructor with no parameters.  Interfaces ITMSLogger and IADGroups are setup to use Dependency Injection with TMSLogger and ADGroups respectively.   The following code works fine but doesn't use dependency injection for class ADGroups. public class BeastAuthenticateAttribute : AuthorizeAttribute { private ITMSLogger logger = new TMSLogger(); public BeastAuthenticateAttribute() { ADGroups adGroups = new ADGroups(logger); Roles = adGroups.GetRolesWithGroup("BEAST"); } } I tried the following but I'm getting an error ("Object reference is required...") with "this (adGroups). public class BeastAuthenticateAttribute : AuthorizeAttribute { private ITMSLogger logger = new TMSLogger(); private IADGroups adGroups;// = new ADGroups(new TMSLogger()); public BeastAuthenticateAttribute() : this (adGroups) { // adGroups = new ADGroups(logger); // this(adGroups); } public BeastAuthenticateAttribute(IADGroups adGroups) { //ADGroups adGroups = new ADGroups(l

Error - No parameterless constructor defined for this object.

I am doing Music Store sample application.Here my code.StoreViewModel public class StoreManagerViewModel { public Album Album { get; set; } public SelectList Artists { get; set; } public SelectList Genres { get; set; } } StoreController public ActionResult Create() { var Artists = storeDB.Artists; var Genres = storeDB.Genres; StoreManagerViewModel model = new StoreManagerViewModel() { Album = new Album(), Artists = new SelectList(Artists, "ArtistId", "Name"), Genres = new SelectList(Genres, "GenreId", "Name") }; ViewData["Artists"] = model.Artists; ViewData["Genres"] = model.Genres; return View(model); } [HttpPost] public ActionResult Create(StoreManagerViewModel model) { try { if (ModelState.IsValid) { Album album = new Album() { Title = model.Album.Title, Price = model.Album.Price, ArtistId = Convert.ToInt32(model.Artists.SelectedValue), GenreId = Convert.ToInt32(model.Genres.SelectedValue),

WPF app never appears if showing a MessageBox during App constructor!?

My App class' constructor calls a method called initDataStructures. Here I want to load a file with data if it exists. However, as always, it's not guaranteed I can access the file - in my case, the most likely situation (it's a CSV file) is that the file is open in Excel. In this case I would like to show a dialog box, and the user can then choose to ignore the problem (and lose previously saved data) or exit the application (to try again after taking some action, such as closing the file in Excel). This code is in initDataStructures(), called from the App constructor: if (File.Exists(SubmissionsFileName)) { try { using (var reader = new CsvReader(File.OpenRead(SubmissionsFileName), ';')) { ... } } catch (IOException ex) { //string nl = Environment.NewLine; //string msg = "IOException caught while attempting to load previously recorded submissions. " // + "Press OK to ignore (lose previously saved submissions), Cancel to exit. " + nl + nl // + "Message: " + nl + nl + "{0}"; //var response = MessageBox.Show(string.Format(msg, ex.Message), "Loading error", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); //if (response == MessageBoxResult.Cancel) //{ // submissions = null; // Shutdown(); //} } } If I uncomment the commented li

Why I get "Constructor supports only the 'Reset' action" on Add in ObservableDictionary with DataG


I replace ItemsSource in DataGrid by new ObservableDictionary (dataGridStatistic.ItemsSource = reportData; on Window_Loaded);.
Why I get "Constructor supports only the 'Reset' action"?

I have error "Constructor supports only the 'Reset' action" when




Private constructor


Is declaring a constructor private or declaring a class sealed is same thing??  Undecided

Workflow Constructor Error: Could not create activity of type '{Workflow}'

If I attempt to new-up a custom class in my Workflow constructor:

_workflowInfo =  
                new WorkflowInfo(workflowProperties.OriginatorUser, workflowProperties.Item,  

... I receive the following error:

Error 1 Could not create activity of type '{Workflow}'. System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
   at System.Uri..ctor(String uriString)
   at Microsoft.Shar

why always display " CssStyleCollection has no constructor function!!!"



   protected void GridView1_Row(object sender, GridViewRowEventArgs e)
        foreach (TableCell cel in e.Row.Cells)
            if (cel.Text.ToString() == "??")
                e.Row.BackColor = Color.FromName("#000084");
                e.Row.ForeColor = Color.White;
                CssStyleCollection mid = new CssStyleCollection();  // display complier error : CssStyleCollection has no constructor function!!!"     But Why????



ArgumentOutOfRangeException from default constructor of Hashtable



We have observed really seldom (not reproduceable) an exception from the default constructor of the Hashtable and wounder how this could happen. The application (WPF UI) uses:

- .Net Framework 3.5 SP1

- Microsoft Composite Application Guidance (October 2009)

- Microsoft Enterprise Library (October 2008)

- WPF Toolkit (June 2009)

- a couple of other libraries that we not yet loaded at the time where one of the two cases was observerd

Since in both callstacks below involve only/mostly code of the .Net Framework I checked the Reference Source and found really no explanation for both exceptions. I can't hardly consider another reason than corrupted memory. I am posting this question here since the second exception occured very early after start of the application, long before we load own native code via P/Invoke. At this time only the Enterprise Library (Logging Application Block) and Composite Application Library are loaded. Searching for similar problems did not bring me forward, but showed that such a problem was also observed by others (http://bytes.com/topic/c-sharp/answers/432054-strange-exception-default-hashtable-constructor and

Unable to unhook an event hooked in Static constructor


One of the static constructor in a class of our project hooks to an event handler, and i tried to placed the code to unhook the event in dispose.

when i try to invoke dispose  method of the class, the object is actually null and unable to invoke dispose.

I tried using Destructor and implementing IDisposable interface, However both the destructor as well the dispose method never get called. Are they need to be called explicitly or am i missing something?. 

Is there any other elegant way to unhook the event handler? 

Note : the event handler is hooked in the static constructor.

Any help would be appreciated.



Vallarasu S.

Object cannot be serialized because it does not have a parameterless constructor


I am creating a web service based on auto-generated classes from a schema compiler and all works well until I try to run the web service.  The service is:


[WebMethod(Description="Requester pings URL of EA to see if it is alive. Returns errorObject(s) as necessary to communicate application status.")]

[SoapHeader("MultiSpeakMsgHeader", Direction=SoapHeaderDirection.InOut)]

public errorObject[] PingURL()


return null;


The class code is:


public class errorObject : Altova.Xml.TypeBase


Private Constructor


In singlton pattarn , how , when the private constructor is called , pls give some practical example

Partial Constructor


how and when a partial constructor is called, who calls the partial constructor

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend