Sunday, November 25, 2012

Portable Class Library and Compability Problems

It's very common these days to develop applications to run in several different platforms. Conventionally, UI and logic are being seperated but still, porting is the problem. In MS enviroment, as you create a class library project (for example at .Net) and want to use it in somewhere else (like Windows Phone) it's not possible to use project directly. Instead, one by one, you have to port your code.

Portable Class Library is a solution to this from Microsoft, a project type that can be directly used at

- .Net
- Windows RT
- Silverlight
- XBox 360 XNA
- Windows Phone

solutions as reference. Of course it's not the field of roses without thorns and having strong restrictions to keep compability between all those platforms.

Portable Class Libraries Contrib is a project at this point to implement some important API's, especially at System.IO and System.Cryptography levels. Normally PCL does not support these API's and Contrib really does a good job about this. At the moment it brings these additional API's to Portable Class library,

Portable.Runtime
System.Net.WebUtility (for encoding/decoding HTML)
System.Diagnostics.Stopwatch
Extension 'Close' methods for IDisposable types

Portable.Reflection
Provides extension methods for retrieving a ICustomAttributeProvider from reflection objects, such as Type, MemberInfo, etc.

Portable.ComponentModel.Async
System.ComponentModel.BackgroundWorker
System.ComponentModel.AsyncOperation
System.ComponentModel.AsyncOperationManager

Portable.Security.Cryptography 
System.Security.Cryptography.AesManaged
System.Security.Cryptography.HMACSHA1
System.Security.Cryptography.HMACSHA256
System.Security.Cryptography.SHA1Managed
System.Security.Cryptography.SHA256Managed
System.Security.Cryptography.Rfc2898DeriveBytes

Portable.Security.Cryptography.ProtectedData (.NET 4.x, Windows Store and Windows Phone 7.5 only)
System.Security.Cryptography.ProtectedData

Tuesday, November 20, 2012

SharePoint 2010 : Failed To Load Receiver Assembly

When deploying the SharePoint solution from Visual Studio, you may sometimes face this error, especially after changing the Strong Name Key of projects.

In that case, you need to go to GAC, copy your project's public key token, and paste this value to your feature's "receiver assembly" string's proper place.

To find "receiver assembly" in properties window, you need to double click on feature and then this window appears.

Tuesday, June 21, 2011

Sharepoint 2010 : Deploying a WSP package to remote server easily

By using Sharepoint Management Console,

1) Uninstall-SPSolution -Identity package.wsp -WebApplication http://server
2) Remove-SPSolution –Identity package.wsp
3) Add-SPSolution "C:\blabla\package.wsp"
4) Install-SPSolution –Identity PernodTC.wsp –WebApplication http://server


Monday, June 20, 2011

CAML & C#

If you are querying a Sharepoint 2010 List with CAML using C#, sometimes you can face inconsistent results. One of the most popular ones is not working OrderBy statements. After querying the list in C# with OrderBy query, you may see that the incoming list is still in default order.

The solution here is simple: In case you are using Query tag in your query string, just remove it. Your querystring should start directly with Where or OrderBy tag and this should solve your problem.

If it still does not, you can add Type field to your OrderBy query. Type="Number" or Type="DateTime" helps CAML interpreter to understand howto sort it. (Well, it should automatically detect it from Sharepoint therotically, yes, but the real life is never easy in Sharepoint)

The last thing in your checklist can be that CAML is a case-sensitive language, you can think about checking your query syntax and capital letters.

Wednesday, June 1, 2011

Sharepoint 2010 and Session

Hello everybody,

It's a known thing that it's not that easy to start working with Sessions when developing custom webparts. It demands several modifications on server etc.

If you have jumped over that issue, you may face further ones about storing objects in Session.
One of the key elements here is being "Serializable" Even depending on your configuration, Sharepoint may allow you to use non-serialiazable classes in session or not.

But if you're facing "unknown error" in your session-using custom webpart, take a look at your session objects and be sure that all of them are serializable ones.

(You can define your all classes with [Serializable] attribute, by the way.)

Wednesday, December 8, 2010

Windows Azure & SQL Azure - A Fresh Start For Development

Microsoft is releasing some free accounts for Windows and SQL Azure these days for their partners. If you have your free accounts, then it's time to start developing something for the cloud.

To just to code a hello world application in Visual Studio 2010, ou need a Windows running IIS and ASP.NET. After installing service packs and cloud tools, it's very easy to create a C# cloud project and adding a ASP.NET web role application to it, then you'll have your first "Default.aspx" and you are free to modify it. After that, by using the management central of Azure (which looks pretty sexy) it's again very simple to publish the compiled application by right clicking on Cloud project and choosing "Publish".

After this step, maybe you need to also do something on SQL Azure.

Be careful: SQL Server Management Tools versions before than 2008 R2 are not fully compatible with SQL Azure, you cannot use "object explorer" though you can open a query window directly. Here the solution is downloading the latest SQL Server Management Studio Express for free.

After that connecting to SQL Azure is quite same like classic SQL Authentication method: From the management console of SQL Azure you'll learn the connection address for your database, username and password. That's it, then from the Management Studio you can create your tables and from ordinary .NET SQL classes, you can connect your application from your ASP.NET application which is compiled for Azure.

Rumors say that Microsoft is spending a very big effort on Bing, Mobile and Cloud these days as they want to keep their positions in the game against Google and Apple. My experience so far is, Windows and SQL Azure are extremely easy to start with, no need to worry.

Tuesday, December 22, 2009

SPFile Item Update Error: Operation is not valid due to the current state of the object.

It's very frustrating and can take a whole working day: You are trying to update a library (list) item from Sharepoint object model and getting this error continiously.

In fact, solution is simple: RunWithElevatedPrivileges is working buggy in Sharepoint 2007, so the best things is avoiding putting code in it as much as possible.

For instance, if you want to simply update "Title" of an item in your document library, it should appear like this;

SPFile FileToModify = null;
SPSite ElevatedSite = null;
SPWeb ElevatedWeb = null;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite Site = new SPSite(SiteCollectionUrl))
{
ElevatedWeb = Site.RootWeb;
ElevatedSite = Site;
}
});

SPItem Items = FileToModify.Item;
ElevatedSite.RootWeb.AllowUnsafeUpdates = true;
Items["Title"] = "new title";
FileToModify.Item.UpdateOverwriteVersion();
ElevatedSite.RootWeb.AllowUnsafeUpdates = false;
Returning = "ok";

--

Then you won't face any errors.