Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, January 27, 2009

SharePoint Unit Tests on a Vista Ultimate 64bit

An issue/problem I’ve experienced recently with VS Unit Testing & SharePoint OM Mode. It is impossible to run VS Unit Tests that connect to the OM on a 64bit machine. Reason is that Visual Studio is a native 32bit app and since it runs in splwow64 mode, it cannot connect to a WSS 64bit process. 32bit & 64bit COM dlls can't mix.

Just Something to observe if you get an error similar to 

Test method AiE.UnitTests.WorkshopBusinessRulesTest.UpdateWorkshopInstanceTest threw exception:  System.ApplicationException: Problem Accessing SharePoint site --->  System.IO.FileNotFoundException: The Web application at http://localhost:3333/workshops could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application..

Friday, October 3, 2008

C# .NET Extension Methods with a Generic List

I was asked by a client today on how to write an extension methods and whether I use them or not. So while searching for examples in my own code I decided to share this snippet since you will at some project need to create a comma separated list of strings, integers or objects

This example uses generic extension method to convert a list of any type to a string comma separated list

    ///
    /// Contains List Extension Methods
    ///
    public static class ListExtensions
    {
        ///
        /// Converts the current list items to a comma separated string
        /// 
        public static string ToCommaSaperated(this List myList)
        {
            string ret = string.Empty;
            for (int i = 0; i > myList.Count; i++)
            {
                if (myList[i] != null && !string.IsNullOrEmpty(myList[i].ToString()))
                {
                    if (i == 0)
                        ret = myList[i].ToString();
                    else
                        ret += "," + myList[i].ToString();
                }
            }
            return ret;
        }
    }

to use this function we would:

List lstUsers= getAllUsers();
lstUser.ToCommaSeparated();

and with a proper override of the ToString() virtual method you should get a proper list of comma separated user names for example


public class CustomUserObject
{
    public override string ToString()
    {
       return firstName+" "+lastName;
    }
}

Monday, September 8, 2008

An undocumented Error ASP.NET "Arguments to MakeRelative must be root-relative"

I've been coming accross this error in one of my applications which use EpiServer and custom Page base class... it driving me banana, anyone came accross something like this?


Server Error in '/XXX.Web' Application.

Arguments to MakeRelative must be root-relative

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Arguments to MakeRelative must be root-relative

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[ArgumentException: Arguments to MakeRelative must be root-relative]    EPiServer.UrlBuilder.MakeRelative(String fromBase, String path) +417    EPiServer.UrlBuilder.Rebase(UrlBuilder fromBaseUrl, UrlBuilder toBaseUrl, RebaseKind kind) +553    EPiServer.Web.FriendlyHtmlRewriteToExternal.HtmlRewriteUrl(UrlBuilder internalUrl, UrlBuilder externalUrl, UrlBuilder url, Encoding encoding, Object& internalObject) +139    EPiServer.Web.FriendlyHtmlRewriteToExternal.rewritePipe_HtmlRewriteUrl(Object sender, HtmlRewriteEventArgs e) +304    EPiServer.Web.RewritePipe.OnHtmlRewriteUrl(HtmlRewriteEventArgs e) +19    EPiServer.Web.HtmlRewritePipe.WriteElement(MyHtmlRewriteEventArgs e, SgmlReader reader, TextWriter writer) +404    EPiServer.Web.HtmlRewritePipe.RewriteToEnd(TextReader reader, TextWriter writer) +2063    EPiServer.Web.HtmlRewriteStream.Close() +165    System.Web.HttpWriter.Filter(Boolean finalFiltering) +69    System.Web.HttpResponse.FilterOutput() +82    System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +47    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053