Debugging External Library In Visual Studio

January 27, 2013 Leave a comment

I was searching on how to debug an external library in Visual Studio, then found this:

http://stackoverflow.com/questions/654696/how-to-debug-external-class-library-projects-in-visual-studio

I just blogged it so I can easily find this again in the future. One thing to note is that you should have the library’s PDB file, which should match the build.

Multiple WebAPI Post Methods

January 22, 2013 Leave a comment

I was working on a WebAPI project and realized that I needed multiple post methods. I have an existing method like this one:

public HttpResponseMessage PostProduct(Product product)
{
}

And I needed another post method that will accept an array. It can be done by using the ActionName attribute.

[ActionName("CreateProduct")]
public HttpResponseMessage PostProduct(Product product)
{
}

[ActionName("CreateProducts")]
public HttpResponseMessage PostProduct(Product[] products)
{
}

That should do it. The URLs to these methods will also change, say from /api/Products to /api/Products/CreateProduct. This will break existing clients. If you want to retain the URL used by the first method, then you can add a new route like this:

routes.MapHttpRoute(
    name: "ProductPostRequest",
    routeTemplate: "{controller}/{action}",
    defaults: new { action = "CreateProduct" },
    constraints: new { controller = "Products", httpMethod = new HttpMethodConstraint("POST") }
);

This just means that the CreateProduct will be the default method for Post requests on the Products controller.

Categories: WebAPI Tags: ,

Inheriting WebClient in Windows Phone

May 26, 2012 Leave a comment

I was working on my Windows Phone app when I encountered a runtime error:

Inheritance security rules violated by type: ‘<class name>’. Derived types must either  match the security accessibility of the base type or be less accessible.  If the base class has a non-transparent default constructor, the derived class must also have a default constructor, and the method inheritance rules apply across those two methods.

It was caused by inheriting the WebClient class. Fortunately, the fix was easy and we just need to specify an attribute to the derived class’ constructor.

public class DerivedWebClient : WebClient
{
    [System.Security.SecuritySafeCritical]
    public DerivedWebClient()
    {
    }
}
Categories: Windows Phone

9GAG Metro Now Published in Windows Phone Marketplace

March 10, 2012 7 comments

My first windows phone app, 9GAG Metro was recently approved and published in the Windows Phone Marketplace. Here’s the link: http://www.windowsphone.com/en-US/apps/927f98ac-ba6b-41ee-8673-eea59e7815f8 . Although there are already a lot of 9GAG client apps in the marketplace, most of them lack features that I want. That is why I decided to create an app. I’m not saying that my app currently has a lot of features. Actually, it is the opposite. But, I can work on new features during my spare time and continuously improve my app. I do have an update already submitted and is waiting for the certification results.

So what is the difference of this app compared to others? The main difference is the image quality of long posts. To ensure that Windows Phone apps perform well, one of the requirements Microsoft set is to have images displayed to at most 2000 by 2000 pixels. Other apps display long posts by scaling them to fit within the 2000 pixels requirement. Unfortunately, some long posts containing text tend to be unreadable after scaling. 9GAG Metro addresses this problem by breaking down the image into smaller images. The trade-off is that it consumes more memory.

Another feature I included is the ability to read comments. Sometimes, there are some posts that you don’t understand. Commenters usually explain the post so I decided it is quite necessary to be able to read comments. Unfortunately, this feature is currently broken and causes the app to crash. I will post a detailed blog post on what caused this. The fix is included in the new update I submitted.

It failed certification once, which I wrote about in a recent blog post: http://mdetras.com/2012/02/25/my-first-submission-to-the-windows-phone-marketplace/ .

Update: Version 1.1 was already published to the marketplace. This includes bug fix for viewing comments, image zoom, and viewing recent posts. Please check http://mdetras.com/9gagmetro/ for details and how-tos.

My First Submission to the Windows Phone Marketplace

February 25, 2012 1 comment

My first app failed testing some time this week. It is a client app for the 9GAG web site. If you are familiar with 9GAG, then you know it is full of adult jokes. Unfortunately, you can’t target a few countries for distribution of your app if it contains these kinds of jokes. And I set my app to be distributed worldwide. I have read the requirements before I submitted but I tried it anyway. Talk about being stubborn.

I also want to share some details of the test results. I got it in PDF format, which was forwarded to me by YallaApps, a global publisher (I am from the Philippines, and it is not yet listed in the App Hub). My submission was received on February 17, 2012, and the testing was completed on February 22, 2012. So, it was completed in 4 working days. The app was tested on 4 different devices: HTC HD7, LG Quantum, Nokia Lumia 710, and Nokia Lumia 800.

The test results also contain the violation/s (I’m not sure if they lists all the violations). My app only got one:

“Content that is offensive in any country/region to which your application is targeted not allowed. Content may be considered offensive in certain countries/regions because of local laws or cultural norms. Examples of potentially offensive content in certain countries/regions include, but are not limited to the following:

  • People in revealing clothing or in sexually suggestive poses
  • Religious references
  • Alcohol references
  • Sexual or bathroom humor
  • Simulated or actual gambling

Countries/regions for which one or more parts of 3.10 may apply include the following:

  • Group 1: China
  • Group 2: Malaysia, Indonesia”

In the comments section, the testers added the steps to reproduce.

  1. Launch application
  2. Navigate between articles using “<-” icon (newer)/”->” (older)
  3. Observe that the application contains adult jokes and includes countries listed in Group 2 within Application Certification Requirement 3.10 in its targeted distribution.

That’s it. I resubmitted my app and selected the appropriate countries in the target distribution. Unfortunately, YallaApps has some countries missing, including the Philippines (which was newly added to the marketplace). I still have yet to contact them regarding this matter.

Displaying Large Images in Windows Phone

February 3, 2012 Leave a comment

I was working on a windows phone app and I needed to show a large image downloaded from the web. I found out that an image should have a max dimension of 2000 x 2000 pixels in windows phone due to performance requirements. I thought of splitting the image into smaller images that will fit the max dimension. To be able to split the image, we need to get its dimensions.

If you used the Image control and set the Source property to the URI of the image, you won’t be able to obtain the original pixel width and height (at least that’s what I know). The BitmapImage source of the Image control might already be downsampled or cropped, so the dimensions won’t be the same as the original. An easy workaround is to use the WebClient class to download the image.

The following is an example code that uses downloads the image using WebClient, splits it into images with a height of 1000 pixels or less, and set them as the ItemsSource of a ListBox with the DataTemplate set to <Image Source=”{Binding}”/>. I used the WriteableBitmapEx library to crop the image. You can download it via NuGet, or the codeplex site http://writeablebitmapex.codeplex.com/.

public partial class MainPage : PhoneApplicationPage
{
    private WebClient webClient;
    private List bitmaps;

    // Constructor
    public MainPage()
    {
        InitializeComponent();

        bitmaps = new List();

        webClient = new WebClient();
        webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
        webClient.OpenReadAsync(new Uri("http://www.someurl.com/someimage.jpg"));
    }

    private void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        var rawBitmap = PictureDecoder.DecodeJpeg(e.Result);
        var xOffset = 0;
        var yOffset = 0;
        var rawBitmapHeight = rawBitmap.PixelHeight;
        var rawBitmapWidth = rawBitmap.PixelWidth;
        while (yOffset < rawBitmapHeight)
        {
            var croppedBitmap = rawBitmap.Crop(xOffset, yOffset, rawBitmapWidth, 1000);
            bitmaps.Add(croppedBitmap);
            yOffset += 1000;
        }
        ImagesListBox.ItemsSource = bitmaps;
    }
}
Categories: Windows Phone Tags: ,

Unable to load DLL ‘SQLite.Interop.DLL’

September 29, 2011 1 comment

I am working on a ASP .NET MVC 3 project and decided to use SQLite. I found a great Code Project article titled SQLite Membership, Role, and Profile Providers by Roger Martin. He made SQLite providers similar to those for SQL Server. I decided to follow the article step-by-step. After build, I opened the Security tab of the ASP .NET Web Site Administration Tool page (via the ASP .NET Configuration item under the Project menu), and got the following error message:

Unable to load DLL ‘SQLite.Interop.DLL’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

It seems that the System.Data.SQLite DLL needs the SQLite.Interop DLL in the same directory. So we’ll just need to copy that DLL to our bin directory. Of course, we would want to have Visual Studio do it automatically for us when we build our project. If you have added the DLL to your project you can set the “Copy to Output Directory” property of the said DLL. That is, it should not be inside a subfolder of the project. Otherwise, the DLL will be inside a subfolder in the output directory.

If the DLL is in a sub-folder we can still use Build Events. In the project properties, go to Build Events and put the following command in either the Pre-build or Post-build event command line (assuming that you have put the SQLite.Interop DLL in a lib subfolder):

Copy “$(ProjectDir)lib\SQLite.Interop.dll” “$(ProjectDir)$(OutDir)SQLite.Interop.dll”

Categories: SQLite Tags:
Follow

Get every new post delivered to your Inbox.