Showing posts with label Csharp. Show all posts
Showing posts with label Csharp. Show all posts

Saturday 19 September 2015

Why String Are Value Types Csharp Dotnet


The distinction between reference types and value types are basically a performance tradeoff in the design of the language. Reference types have some overhead on construction and destruction and garbage collection, because they are created on the heap. Value types on the other hand have overhead on method calls , because the whole object is copied rather than just a pointer.

Because strings can be  much larger than the size of a pointer, they are designed as reference types. Also, as Servy pointed out, the size of a value type must be known at compile time, which is not always the case for strings.

Strings aren't value types since they can be huge, and need to be stored on the heap. Value types are stored on the stack. Stack allocating strings would break all sorts of things: the stack is only 1MB, you'd have to box each string, incurring a copy penalty, you couldn't intern strings, and memory usage would balloon, etc

That is why a string is really immutable because when you change it even if it is of the same size the compiler doesn't know that and has to allocate a new array and assign characters to the positions in the array. It makes sense if you think of strings as a way that languages protect you from having to allocate memory on the fly 

Friday 2 January 2015

Nopcommerce Developer Guide


Internship - Day 1


Today was first day of my internship Period of 6 months . I am very happy to start my internship with Abax Technologies . Abax technologies is a recognized IT company Situated in Noida . It deals with Desktop , web and Mobile application development and providing solutions to market .

Mr. Rohit Jain is CEO of Company and I am doing Internship under their guidance .

Now came to work -- On 2nd January - 8:23 am Rohit Sir posted my first task on skype . My first task was first to learn more about Nopcommerce , Its Architecture , Plugin development , Module Development , Theme development and widget development .

First i need to download the source code for Nopcommerce form Nopcommerce office webiste then using that source code to compile it , set up its database then run a demo site in nopcommerce .

After setup the demo site for nopcommerce it started exploring its source code architecture and learn more about it from its developer's documentation

I have previously done a ecommerce website in Nopcommerce but at that time i used Nopcommerce 1.9 version that was asp.net version of nopcommerce Now i am going to use Nopcommerce 3.2 and this version is really cool . It is MVC version of nopcommerce using Linq queries instead of using sql and using Razor view engines and more flexibility . Actually I liked this version .

Important Links that i have studied and explored today -

Link for Nopcommerce Developer's Documentation
Nopcommerce Developer Documentation



Nopcommerce uses code first approach for each and every development component in nopcommerce so i decided to first give a look at code first approach to revise my concepts about codefirst approach

Code First Approach Documentation MVC


After Reading about code first approach of Nopcommerce I reached a Nerd Dinner app that is MVC app that uses code first approch for MVC application development
Nerd Dinner MVC App with Code First Approach

So that was it for the day i learned number of things today

Today I have explored following Modules -


1. Nopcommerce Installation v3.20 (mvc)
2. Explored Nopcommerce Developers Documentation
3. Exploring Nopcommerce Architecture
4. Explored Nopcommerce Theme CUstomization and Creating Own Theme
5. Exploring Plugin Development Documentation
     -- Created simple hello world Plugin

Next I will explore create plugins with database access and various nopcommerce inbuilt modules

Tuesday 23 December 2014

Pass Data between Activity in Android


Hello Friends ,

Today I got one message from a person to tell him how to pass data between android activities So, I am going to give a simple way for how we can transfer data or how we can pass data across activities in android . In android we use activity for  each layout code .

I am using Mono Android for this article but that will similar functions in Dalvik android that is used with java based android applications .

Here are simple Steps How to Pass data between Activities in Android Using Csharp -

  1. Open Visual Studio . Click on File --> New Project -->
  2. Now choose Mono For Android and click on Android Application . Now Simple Android application will be created
  3. This project will create a single activity named MainActivity (MainActivity.cs), which contains a button.
  4. Add a second New activity class named Activity2 to the project. by right click on Solution Name and click on New then click on Android Activity leave the name as default and click on Ok  This class must inherit from Android.App.Activity .
  5. right click on layout folder inside Resource folder then click new and choose Android Layout give it a name and leave as default and click ok .
  6. In the button.Click handler in MainActivity.cs , create an intent for Activity2 , and add data to the intent by calling PutExtra and this data given in Put Extra will be transfered to Activity2 . Add the Code Below for that :-
 button.Click += delegate {
               // button.Text = string.Format("{0} clicks!", count++);
                var activity2 = new Intent(this, typeof(Activity2));
                activity2.PutExtra("MyData", "Data from Activity1");
                StartActivity(activity2);
            };
      
      7. Now Open you layout.xm file in Resource --> layout folder ( layout folder under resource folder ) . Add code below to it for Adding button under <linearlayout> tag :-

        <Button
        android:id="@+id/MyButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/Hello" />    string text = Intent.GetStringExtra

    8. Now add code below to Newly added Activity - activity2.cs under Activiy.Oncreate Method :-
            ("MyData") ?? "Data not available";
            string text1 = Intent.GetStringExtra("MyData");
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            button.Text = text;

       9. Now Run the app by pressing F5 and see the output in emulator as below -
Pass Data between Activity in android 
10. Now click on button saying "Hello World,Click Me!" Now you will see New Avtivity Activity2 as below that contain the text that we have passed from activity Activity1

Pass Data between Activity in android 


Saturday 4 October 2014

\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe is invalid

When your are using Android with Csharp or when you are using Monoandroid you will be facing some some error related to aapt.exe missing or aapt.exe invalid . These are common error to Monoandroid developer that almost every one that uses Monoandroid will face .

So Today I decided to get the actual reason of this problem and I sit on my chair to find out the reason and possible solution to this error that may work for everyone . I suffered from this error number of times before but i tried the ways to get rid of it But not today this is the day to get solution of this error .

What are Possible Errors :



  • Error MSB6004: The specified task executable location "C:\Program


  • Files\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe" is 


invalid. (MSB6004) (TaskyAndroid)

The specified task executable location "D:\android-sdk\platform-tools

\aapt.exe" is invalid.


Reason of Above Errors 




This issue is caused by Google changing around the directory structure of the Android SDK with their latest updates and due to these updates old directory structures are creating problem Most probably these error comes after you update your android So when you update your android-sdk then it update the directory structure of android-sdk to new structure of google that allows
aapt.exe to be must present in android-sdk/platform-tools/ but that will be not there because in old directory structure that monoandroid is using aapt.exe is in android-sdk/build-tools/ that's why this error is coming and MonoAndroid Team is applying these changes so  before that we need to figure out this issue to continue our development

Error Solution aapt.exe Invalid


Steps :-

1.  Copy the aapt.exe file from folder \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools . Here 17.0.0 is your android api you have installed in your sdk it will be what version you installed like :- 8.0.0, 18.0.0

2. Now Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin

3. Now Everything will be fine ........Cheers!


There is one more error which can let you suffer it is :-

java exited with code 1


Reason of Error java exited with code 1

The reason of this error is in our previous error solution When you copy the aapt.exe file from  \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools .  and forger to copy or don't copy folder  \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ then this error comes this is main reason of this error

Error Solution java exited with code 1



 Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin after copying aapt.exe file

Wednesday 20 August 2014

save to google drive button javascript code

This is a simple javascript code to upload file from your computer to google drive using google drive api

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   <script src='https://apis.google.com/js/platform.js'></script>
<div class="g-savetodrive"   data-src="/images/attendance.png" data-filename="ppupload1.jpg" data-sitename="Pictures of "    >
</div>
    </form>
</body>
</html>


Sunday 3 August 2014

Mixed mode assembly is built against version 'v2.0.50727' of the runtime


Error :- Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information

Error Explanation -
During using Sqlite Database with Csharp Applications you may suffer from this error Don't fear from it this is simple error

This problem is seen often . The main reasonof this problems  is that, because of the support for side-by-side runtimes in .Net Technology , .NET framework 4.0 has changed its way of binding  to older framework mixed-mode assemblies. These assemblies are those that are compiled from old  C++\CLI. Currently available DirectX assemblies are mixed mode. If you see a message like this then you know you have run into the issue:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

SOLUTION :
Add the Following code in App.config file . App.config file will be available in Solution Explorer . If App.config is not available then you can add it by :-

  1. Right click on Project's folder in Solution Explorer 
  2. Click on Add then click on New
  3. Now scroll and find Application Configuration file and Click ok
  4. Now App.config will be successfully added .
  5. Now make the code of your App.config file similar to the following code or the replace the <startup> tag with tag given below

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     <requiredRuntime version="v4.0.20506" />
    </startup>
  6. Now All errors Will be gone and continue your code with SQlite Csharp using link below :-

    How To Use Sqlite Database With Csharp