Could not load file or assembly ‘Microsoft.Sharepoint.Sandbox, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

So i created a standard ASP.NET WebService Application, referenced the Microsoft.SharePoint.dll and created a WebService method that returned the current logged-in user – nothing out of the ordinary. Then i tried to start the web service out of visual studio and got the following error message:

 

I didn’t really know why it said it couldn’t load the Microsoft.SharePoint.Sanbox.dll because i didn’t even reference it. I tried to remove the Microsoft.SharePoint.dll from my references and it still gave me this error – weird.

After a bit of digging around what might could have gone wrong, i noticed that the Sandbox.dll somehow ended up in my WebService’s bin folder. So i went with the most pragmatic solution – i deleted the .dll, rebuild the project and everything started fine.

Still don’t know whats wrong, but hey – it works.

The Exception Unkown

 

 

 

 

 

 

well, thank you Visual Studio.

Google Authorized Access

This page shows all 3rd-party tools or applications that have access to your google account data – just posting because i keep searching for it every once in a while ;-)

 

a.

SharePoint 2013 System Requirements

 

yes, 24gb ram…

 

a.

Fixing the “site template requires that the feature…” Error with Powershell

We have a custom ASP.NET web service that allows use to create SharePoint-Sites (SPWeb’s) based on a template. Today i was getting some weird errors when i tried to use it.

Well, fair enough, i understand why it’s failing – it even makes sense. The template had activated features that the SiteCollection (RootWeb) didn’t had. Looking up all features and comparing the GUIDs to find the one i needed was too time consuming and boring, so i decided to speed it up a little with the following Powershell command (btw. i really LOVE powershell!)

With this command i was able to activate the feature in my root web with ease – turns out that this wasn’t the only feature that wasn’t activated – i had to active 7 other features.

over and out,

a.

 

Linux Commands

so i just got my own vps running debian, and i’ll post some commands i’ll be forgetting ;-)

- passwd (changes password)
- cat /proc/meminfo (shows memory information)

over and out,
a.

SharePoint WebService Reference in your Client Applications

Just posting this because i always keep forgetting it ;-)

To add a SharePoint WebService reference (Lists.asmx in this case) to your client application i.e. console app you have to do the following steps:

    1) Add the Lists.asmx reference to Visual Studio as you are used to – http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx
    2) Change app.config from

    to
    3) Now, when you are calling the web service via code, add the following:

    [c#]
    using(var client = new ListsSoapClient())
    {
    client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
    client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

    //perform a operation
    var data = client.GetListCollection();
    }
    [/c#]

that’s it.

a.

How to detect a mobile device in ASP.NET

In a hobby-project (ASP.NET app) i wanted to display different user controls when the user would connect with a mobile device. This is my method to detect whether a connected device is mobile or not:

[C#]public static bool IsMobileDevice(string userAgent)
{
string[] mobiles = { “w3c “, “acs-”, “alav”, “alca”, “amoi”, “audi”, “avan”, “benq”, “bird”, “blac”, “blaz”, “brew”, “cell”, “cldc”, “cmd-”, “dang”, “doco”, “eric”, “hipt”, “inno”, “ipaq”, “java”, “jigs”, “kddi”, “keji”, “leno”, “lg-c”, “lg-d”, “lg-g”, “lge-”, “maui”, “maxo”, “midp”, “mini”, “mits”, “mmef”, “mmp”, “mobi”, “mot-”, “moto”, “mwbp”, “nec-”, “newt”, “noki”, “oper”, “palm”, “pana”, “pant”, “pda”, “phil”, “phone”, “play”, “port”, “prox”, “qwap”, “sage”, “sams”, “sany”, “sch-”, “sec-”, “send”, “seri”, “sgh-”, “shar”, “sie-”, “siem”, “smal”, “smar”, “smartphone”, “sony”, “sph-”, “symb”, “t-mo”, “teli”, “tim-”, “tosh”, “tsm-”, “up.browser”, “up.link”, “upg1″, “upsi”, “vk-v”, “voda”, “wap”, “wap-”, “wapa”, “wapi”, “wapp”, “wapr”, “webc”, “windows ce”, “winw”, “winw”, “xda”, “xda-” };

foreach (string mobile in mobiles)
{
if (userAgent.ToLowerInvariant().Contains(mobile))
return true;
}

return false;
}
[/C#]

You would use the code as followed:

[C#]
if (HttpContext.Current != null)
{
if (IsMobileDevice(HttpContext.Current.Request.UserAgent))
{
//display mobile controls
}

else
{
//display regular controls
}
}
[/C#]
I know i know… the performance is rather bad, but i don’t think there is actually a better way to do this. If you know one though, please let me know.

over and out,
a.

Letter Occurrences in Source Code

So my girlfriend was watching Antitrust last night (pretty bad movie to be fair) and today she asked me if the semicolon was actually the most used character by a programmer on the keyboard. I really had no idea, as i never really paid attention to stuff like this, so i got my fingers dirty and pushed out some code to count the letter occurences in a C# source file :-) Here is the code:

[c#]
//path to the current (this) source file
var path = new System.Diagnostics.StackTrace(true)
.GetFrame(0).GetFileName();

//read the content from the text file
var content = File.ReadAllText(path);

//select all individual chars and group them
var counts = content.GroupBy(c => c)
.Select(g => new {Letter = g.Key, Count = g.Count()}).ToList();

//sort the list by count (asc)
counts.Sort((a, b) => b.Count.CompareTo(a.Count));

//print
counts.ForEach(c => Console.WriteLine(“‘{0}’ was used ‘{1}’ times”, c.Letter, c.Count));

Console.Read();
[/C#]

The code reads the content of the executing *.cs file, groups it by letter and occurences, sorts it and prints it to the console.

easy peasy.

a.

ASP.NET WebService Method Overloading

I recently had the requirement to create a web service (ASP.NET) which was supposed to have only 1 method, but different signatures. So i just went ahead and tried what seemed natural to me:

[c#]
using System.Web.Services;

namespace MyNamespace
{
[WebService(Namespace = "http://mynamespace/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]

public class MyService : WebService
{
[WebMethod]
public string Hello()
{
return Hello(“World”);
}

[WebMethod]
public string Hello(string yourName)
{
return string.Format(“Hello {0}!”, yourName);
}
}
}
[/c#]

and… boom, received the following error message:

Both String Hello() and String Hello(String) use the message name 'Hello'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.

So i changed the code to the following:

[c#]
using System.Web.Services;

namespace MyNamespace
{
[WebService(Namespace = "http://mynamespace/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[System.ComponentModel.ToolboxItem(false)]

public class MyService : WebService
{
[WebMethod(MessageName = "HelloDefault")]
public string Hello()
{
return Hello(“World”);
}

[WebMethod(MessageName = "HelloYou")]
public string Hello(string yourName)
{
return string.Format(“Hello {0}!”, yourName);
}
}
}
[/c#]

and it worked.. and even made sense (doesn’t happen often unfortunately).

Now i just have to test if the data-connection is correctly generated when i add the web service to InfoPath.

[Edit]
Nope, InfoPath can’t seem to get this to work. Well, back to the drawing board.

a.