VS 2010 native code static linking

by APIJunkie 18. May 2011 06:36

This is a heads up for any one that is used to auto link static libraries using project dependencies.

VS 2010 changed the game by adding a new step that is necessary in order to auto link static libraries.

It is not enough to specify project dependencies as we used to do in older versions of Visual Studio.

To setup auto linking go to Project/Properties/Common Properties/Framework and References/Add new reference.

Tags:

C | C++ | Static | Tips and Tricks | Troubleshoot | Visual Studio

How to access an ASP.NET Session object inside a static function (error CS0120)

by APIJunkie 11. January 2008 11:18

If you are trying to access an ASP.NET Session object from inside a static function you will encounter error CS0120:

"An object reference is required for non static field, method, or property... "

The problem is that the Session object is a non static member of the Page/Control class you are using.

When you are inside a static function you do not have access to non static members of your class.

Example:

// this function is ok inside a page or control

void testFunc()

{

  Session["test"] = "testString";

}

// this function will produce an error inside a page or control

static void testStaticFunc()

{

  Session[
"test"] = "testString";

}

The solution to the problem is to access the Session object from another static object/function that has access to the current Session object.

Enter  HttpContext.Current.Session -> http://msdn2.microsoft.com/en-us/library/system.web.httpcontext_members.aspx

The Session object obtained from HttpContext can be used from inside a static function since HttpContext.Current is a static property.

Here is an example of how to use it:

// this function is ok inside a page or control

static void testStaticFunc()

{

  HttpContext.Current.Session["test"] = "testString";

}

 

Tags:

ASP.NET | Session | Static

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon