Tuesday, October 15, 2013

AccessViolationException: Attempted to read or write protected memory - COM libraries

Hello,

In one of my project I have a .NET library that is registered to COM in order to be used from a C++ library.
Due to some error, I had to change the interface of an type; I added a new property ID and I set the type of this ID property to be int.
Once testing was done, I deployed the library in production and I started to see the following error:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. T
his is often an indication that other memory is corrupt.
   at System.String.wstrcpy(Char* dmem, Char* smem, Int32 charCount)
   at System.String.CtorCharPtrStartLength(Char* ptr, Int32 startIndex, Int32 length)
   at System.StubHelpers.BSTRMarshaler.ConvertToManaged(IntPtr bstr)
...

The source of this error was pretty obvious (since the modification I stated earlier was the only one).
I remembered that the type in which I've added the new property ID is mapped to an Entity Framework type (using AutoMapper) and in this entity the ID was of type decimal. After changing the type from int to decimal, the AccessViolationException was gone...

:|

Sunday, October 13, 2013

Programming languages guide (on Apple AppStore)

My second app was approved on Apple AppStore.
You can find it here.

For support and questions, please comment here!

Friday, September 13, 2013

Technical Dictionary En-Ro App (on Apple AppStore)

Hello,

One of my apps was just approved and you can find it here.

For any questions or issues, please comment here!

Thanks!

Tuesday, September 3, 2013

Create/distribute iOS apps (Cordova/PhoneGap)

Hello,

A while ago I've started creating some mobile apps. Since native development (Java/Objective-C) can take some time, I decided to learn an HTML5 mobile framework. One of the most popular (and free/OSS) frameworks is Apache Cordova. You can learn a lot about Cordova on the web...

Since I've wanted to publish some apps, I've also had to became an Apple Developer, buying an Apple Developer ID/Subscription for iOS apps. After that I was able to connect to Member Center and iTunes Connect to configure my account.

Back to the technical part... Once I finished testing the app on the simulators, I had to create an archive of distribution. The first problem I encountered was CopyPNG error. Since I've created the images on Windows, the build process was unable to copy the png images. In order to fix this I had to open the png images in the Preview app and Export them to png and override the images.
After all images errors were fixed, I got another error during linking because libCordova.a was not found (this is actually a bug in the PhoneGap project template). The solution here was to properly set the path to libCordova.a:
- Go to project settings and Build Tab. Search for "Other Linker Flags"
- Double click on the linker flags for Release and Change ${TARGET_BUILD_DIR}/libCordova.a to ${BUILT_PRODUCTS_DIR}/libCordova.a.
Do a clean... build... and an Archive.

Now I am able to test the app on the device and publish it!

Happy coding!

P.S. I also had some problems when I've entered my banking account information... In Romania it's enough to have only the IBAN + name but iTunesConnect wanted the bank account number (which I thought it's the same as the IBAN). After some trials and errors (and a lot of google searching) I came with nothing - the iTunes Connect kept saying that the bank account number is 16 characters long and it's verified against the IBAN; I tried various configurations and none worked... Around 2 AM I decided to go to sleep and go to the bank next day and ask them about my bank account number. But in my way to the bed, I thought that if I remove the first 8 characters (which identifies the country and the bank) I'd get something that something that must identify me. The next day I tried my last idea and it worked. So it looks like the bank account number are the last 16 characters in the IBAN.(at least this works in Romania)

Thursday, March 21, 2013

Freeze/persist ASP.NET GridView header (with images)

Hello,

From time to time we all get a nasty task like 'freeze the grid header and if it is possible do it for most browsers'.
In my case the grid was and ASP.NET WebForms GridView. There are many solutions online (jQuery plugins of some CSS stuff) regarding this but in my case none of those worked by default. What was different in my case was the header; the header cells were some images generated by some aspx file.
The default behavior of the solutions I found was that the header was not in sync with the text cells. This happens because the images were not loaded when the table element (the gridview) was generated.
These are the steps that worked for me:
1. Set the GridView to have thead as header and tbody as body. In RowDataBound set the GridView.HeaderRow.TableSection = TableRowSection.TableHeader;
2. Use the idea from here: http://css-tricks.com/snippets/jquery/persistant-headers-on-tables/
3. Modify a little bit the code to wait for loading images and then modify the width of the th elements:

    window.onload = function () {
        $("table.tableWithFloatingHeader").each(function () {
            $(this).wrap("
");
            $("tr:first", this).before($("tr:first", this).clone());
            clonedHeaderRow = $("tr:first", this);
            clonedHeaderRow.addClass("tableFloatingHeader");
            clonedHeaderRow.css("position", "absolute");
            clonedHeaderRow.css("top", "0px");
            clonedHeaderRow.css("left", "0px");
            clonedHeaderRow.css("visibility", "hidden");

            var row_ths = $("tr:nth-child(2)", this).children("th");
            var crow_ths = $("tr:nth-child(1)", this).children("th"); ;

            for (var i = 0; i < row_ths.size(); ++i) {
                crow_ths.eq(i).width(row_ths.eq(i).width() + 2);
            }
        });

That's about it!


Friday, February 15, 2013

ADO.NET EF duplicates/overrides data (Oracle)

Hello,

In my current project we are using ADO.NET Entity Framework 4 (Oracle implementation).
Today, one of my users noticed that in some data grid the rows were duplicated (that was in the UI).

I found out the LINQ query that got the data from the DB and there's nothing wrong with it (at a glance). Running the equivalent (not the one the EF generates) SQL query, brought back correct data. Debugging on the server revealed that the data was indeed duplicated (actually, it was overridden - the second row was the same as the first). This gave me the idea to look inside the model. I looked inside model's PKs of the generated and it looked like there were wrongly generated - 6 columns were PKs.

The solution was to put only one PK (fortunately I had such a column) and fix some null columns errors.
If you don't have one, you can generate one - see previous post!

Now the data is the same as the SQL query returned.

Happy day...! :)

Thursday, January 17, 2013

HRESULT: 0x80010105 (RPC_E_SERVERFAULT)

Hello,

My current project is using ASP.NET Webforms and we are using a COM component for some simulations.
During some UI integration tests, we got the error from the title: HRESULT: 0x80010105 (RPC_E_SERVERFAULT) during a call to the COM component.
Obviously, I tried reproducing the error on my development machine but the error was nowhere to be found - everything worked!
After a quick search on Google, I've encountered this article (http://msdn.microsoft.com/en-us/magazine/cc163544.aspx) where the solution is presented: set the AspCompat="true" in the @Page directive of the ASP.NET page.
Once I've done that, the error dissapeared!

Hope it helps some of you... :)

Happy coding!