Error Readout:
System.IndexOutOfRangeException:
Fix:
I encountered the above error when I tried to run the query, SELECT MAX(expression ) FROM tables WHERE predicates;
and then loop through the results using a datareader with code like this, while(rdr.Read()) { someLabel.Items.Add(rdr["ColumnName"].ToString()); }
I got the error above, because when you do a "max" sql query it doesn't return any column header. All you need to do is give the sql result set a column header.
SELECT MAX(expression) as "ColumnName" FROM table where predicates; Explanation:
This is another one of my bone head mistakes. It's such a simple little thing I overlook, and gets me so disappointed in myself when I realize I spent time trying to figure this out. It's generally followed by me looking over my shoulder and seeing if any of my peers saw it. I'm mostly blogging this in hopes I won't make a silly mistake like this again .
Why is it always the baby errors that hang me up the most? It can never be something deep in the CLR, or possibly find a mistake in .Net. Nope, noway, not gonna happen .Net is pretty solid...for the most part.
Error Readout:
None, it's not an error silly. The Problem:
When I debug, and look at a string that contains my file path I see 2 backslashs (escape characters) in my string when I only wanted 1. The Solution:It's nothing, don't worry about it, that's just the way Visual Studio "debug" shows your path when you catch it while debugging. When the path is used in the code for the file system there will only be 1 backslash and it will work correctly. This is such a stupid little thing, but for some reason every once in a blue moon, I forget and freak out on why it's doing this, thus wasting a solid five minutes of my life. I put this post up in hopes I will never forget again and that if someone happens to Google this, my post will pop up and help them move on quickly....maybe only wasting 1 to 2 minutes. :)
 It's a good question. There are some types that are not derived from NSObject, these types are called "Primitive Types." Some examples of these types are - int
- bool
- short
- long
- double
- char
Sooooo basically any type that is not derived from the NSObject class is a Primitive type and does not require a "*". Now I bet you are wondering how do I figure out if it's a primitive type or not. - An easy way is to look at the color of the syntax in xCode, is it deep blue or a sky blue? Deep blue = primitive type, but this is not entirely reliable as the standards for coloring syntax can fluctuate or change.

- You can option-click on the object after you have typed it in xCode, click the little book in the upper right hand corner, when the class reference viewer comes up, look and see if it inherits from NSObject. If it doesn't it's Primitive and you don't need a "*".

 Note:There are some alternatives to using the primitive type int, such as the reference type NSInteger, which has
some nice baked in functionality of distinguishing between 32 bit and 64
bit, but not all primitive types have an alternative reference type in Objective C. Just for fun:In .Net they have primitive types too(I believe they call them value types), kinda. The compiler recognizes traditional primitive types and therefore lets you use the syntax int i = 5;But despite the compiler letting you do this, this type still maps back to System.Int32. All things in .Net are mapped back to System.Object. Everything is a reference type, but .Net lets you keep the traditional syntax instead of writing: System.Int32 i = new System.Int32(5);
What a wild month! London, Paris (loved Paris), and Barcelona, followed up with a gig in Philly working for the second biggest software developer in the world on their up front website, SAP.com. Before I dive into the limited aspects I can speak about SAP.com's technology I would like to point out the facet of SAP that has had, and will have, a lasting effect on me, the cafateria. These people (SAP) treat their people good! Made to order sushi, made to order Thai, a Philly cheese steak that will challenge South Philly's finest and a Starbucks that feels like it was made just for me, all this within a short walk from my desk. Really, next to the BMW the Germans know how to do it.
Lets dive into my first day. I was sitting at my desk, after enjoying my oh-so-delicious lunch of Alaskan Cod; I hear this loud noise getting louder. Turns out it was a helicopter flying in with the American Co-CEO. As he gets out, much like a scene you might expect to see from Iron Man, he has a dream effect on me. He waves at the people there to greet him and follow's up with a mock gun shot (I can only hope he made the clicking sound that goes with the mock gun shot) at one of the security guards as he steps into the Escalade, in my mind I say YES, awesome! I know right then and there I'm going to love it for my limited time here.
I digress lets talk about a website that needs to address more nations than a senator trying to get votes in NYC. In short, because this is all I will say and feel comfortable, they follow a Model View Presenter (MVP) development process in making their site. SAP's site addresses content based on what nation/region you are coming from all while maintaining a similar look and feel for every end user. Think localization is easy with .Net...not on this scale boys and girls! Now add a level complexity comprising of several teams in more countries than you can count on one hand, developing for this one site. To create a level of consistency across so many sites a template format was built and an engine on top of the .Net engine to address what should be displayed....this is all I will give up, but I can say it's fun and challenging.
Thanks to VML for making this small yet, incredible contract, possible.
The Problem:
Getting a Powershell script to run a batch script.
The Solution:
powershell.exe -noexit d:\<path to my batch script>\Reporting_Code_Load.bat
Explanation:
All you need to do is add the line above as is to your Powershell script. The "-noexit" tells the command prompt to stay open, simply remove it if you don't want the command prompt to open.
 If Scott Hanselman lives and die's by unit tests, why don't we all just fall in line? It seems the nerd community, has an uncanny ability to adopt silly things quickly. Things like xkcd.com or the idea of ninja's. I have yet to laugh at one xkcd or understand how ninja's are relative in any shape or form, because of this I felt I needed to read up on unit tests, specifically for C#, to find out if it's just hype or this is something development shops with a strong QA team really need to look at.
I read two books that covered the topic of unit testing. The first book was Foundations of Programming (recommended by Scottie H. himself and is free) and the second is Pragmatic Unit Testing In C# with NUnit. Both of them start off with the same old song and dance on how you might have up front costs of introducing unit tests to your code, but the stability these tests provide over the duration of your codes lifetime will cause such dramatic cost savings for the company, it would be foolish not to explore the idea. What a compelling sales pitch, a pitch salesmen, for just about any technology, have used since the beginning of technology in businesses. I'll cut all the used car salesman tactics out and state the most intriguing argument to unit test. It increases code stability and it's easy.
The next question I asked myself: What do I exactly test in the code-base I am working on? In Pragmatic Unit Testing (PUT) they give us an acronym to use in order to answer this question. BICEP.
BICEP, breaks down as such.
Boundary Tests
Inversion Tests
Cross Check Tests
Error Tests
Performance Tests
These are the 5 major aspects one should test, according to PUT and it provides unit testers with a place to start. The next major topic in discussing how to test code is decoupling one piece of code to another. Does your code talk to a middleware? How do you test if middleware is not done creating your service to consume or if middleware is down? In steps NUnit Mocks, NMock2, and DotNetMock. These 3 mock frameworks provide the developer with the ability to feed your tests predefined values, values decided by you. Without going into how to use these mock frameworks, I believe that outside of a few isolated situations they should not be used. The entire purpose of testing your code is to test that you are getting information back that fits the criteria you are looking for. If this information, that is beyond your control, changes on whatever level for whatever reason, you as a developer need to know. Putting in mock objects hides this.
Since I work for a web shop, the topic of web UI unit tests interested me. PUT recommend using Selenium. This makes sense because it still uses the nunit style of testing keeping all your tests to one testing style. Selenium seems a bit cumbersome in comparison to WaitN or iMacro, but I feel keeping all your testing in the same style outweighs the cons of not using Selenium. The more desperate testing sources you introduce, the more confusing it is for an outsider to step in and see the whole picture when learning the code, especially when it's not contained in a single solution.
Finally, I recommend reading both of the books mentioned, but lets be honest most of us care so little about unit testing we'll be lucky to read all of 1 of these books let alone all of both. If this is the case I recommend PUT, while the first few chapters read like the high school teacher striving to gain his students social acceptance, it's an easy read and you can jump into the book at nearly any chapter and get the exact information you are looking for on unit testing. This is something I wish all programming books could achieve.
Error Readout:Exception: System.Web.HttpException Message:
Authentication of viewstate failed. 1) If this is a cluster, edit
configuration so all servers use the same
validationKey and validation algorithm. AutoGenerate cannot be used in
a cluster. 2) Viewstate can only be posted back to the same page. 3)
The viewstate for this page might be corrupted. Source: System.Web at System.Web.UI.LosFormatter.Deserialize(String input) at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()Fix:
I encountered the above error the other day. Since the server wasn't on
a web farm I was a little confused. The fix I ended up using was
updating the web.config key to
requiressl=trueExplanation: The next
thing I asked myself was how can that key affect the viewstate. With
some serious investigation into viewstate and best practices I finally
made the link of how our applications viewstate is tied to session
state which is tied to SSL
when the session cookies are encrypted manually, a step (encrypting our own
session cookies manually) we did because we are still running asp.net 1.1. How to manually encrypt the sessionid in a cookie Response.Cookies["ASP.NET_SessionId"].SecureLets
dive right into how session state and viewstate work to get a better
understanding of the solution. ASP.NET session state lets you associate
a server-side string or object
dictionary containing state data with a particular HTTP client session.
A session is defined as a series of requests issued by the same client
within a certain period of time, and is managed by associating a
session ID with each unique client. The ID is supplied by the client on
each request, either in a cookie or as a special fragment of the
request URL. [ http://msdn.microsoft.com/en-us/magazine/cc163730.aspx] In
.net 1.1 there is a property called "ViewStateUserKey" located in the
viewstate, this key adds user-specific information to the view state.
When the request is
processed, ASP.NET extracts the key from the view state and compares it
against the ViewStateUserKey
of the running page. If the two match, the request is considered
legitimate; otherwise an exception is thrown. In our application we use
the Session.SessionID to set the property. This is where my problem starts. When
a user fills out a form utilizing viewstate to create an account to
login to our system the user establishes a viewstate in their asp.net
page. In order to make the view state slightly more secure we give the
viewstateuserkey
the same value as the session ID. The session ID is a much better fit
because a session ID is unpredictable, times out, and varies on a
per-user basis [ http://msdn.microsoft.com/en-us/library/ms972969.aspx] Once the user has completely filled out the form, we authenticate them. This is where my error occurs [See beginning of post]. The
error is caused because the session id is now encrypted. It's encrypted
because our security team said, all information stored in cookies is to
be secured. Our team consequently set up a flag in the global.asax file
that states if this flag is set to true it should grab the session id
out of each cookie and encrypt it. The reason we did this by hand
is because asp.net 1.1 does not offer secure cookies with one easy key
change in the web.config [NOTE: In asp.net 2.0 all you have to do is have the requiressl=true and you are done]. Now understanding that our session ID is tied to our viewstateuserkey you can understand the viewstateuserkey
is now invalid because the session ID is a different value, simply
because it's encrypted and the server does not know to decrypt it.
[ NOTE: The session ID may still be the same value, it's just
encrypted.] Now asp.net states the viewstateuserkey is invalid and pumps out the error you have seen above. To
fix this I simply change requiressl=true in the web.config. How does
requrie ssl affect an encrypted session id within a cookie that I set
to encrypt? Well, when requiressl
is not on but you are sending the server a secure cookie value, which
we did since we created our own secure cookies in asp.net 1.1 the
server doesn't know to decrypt the cookie because requiressl is not turned
on [ apparently you have to send secure cookies over ssl in asp.net 1.1 and possibly other run times, I didn't know this] which in turn invalidates the viewstateuserkey because the viewstateuserkey uses the session ID which is encrypted in the secure cookie. What
made
this confusing for me is the first part of the form worked without
a hitch. It's when the user authenticates when the error arose. The
reason for this being that the requiressl key is not applicable until
authentication happens. If you'll notice the requiressl key is nested
in the authentication element in the web.config file. Additionally we
don't encrypt the cookie until the user is authenticated. Sooo, the
first few postbacks for our page were just collecting information. It
wasn't until we authenticated the user to our system that requiressl
actually cared if we had secure cookies or not. OverviewViewstateuserkey is set to the session ID. Session ID is encrypted and the updated value is set to the viewstateuserkey requressl
being turned on tells the server to decrypt session id in which case
allows the viewstateuserkey to remain valid with the server.
Jumping right in. The instructions on the dasBlog website of how to install dasBlog on a shared hosting environment are close to zero. The discussion boards offer some insight but in order to get some real feedback you had to post the question, wait and hope they reply soon...if ever.
I will start by showing you the painful way of installing dasBlog on a shared hosting environment and end with showing you the painless way on Godaddy.
Painful starts Below:
- Getting the Code and Getting it to Your Hosting Provider (Godaddy)
Get the code from dasBlog. Download the "web files" unless you want to tinker with the source, a topic I don't cover.
Unzip the code and pull out the "dasblogce" folder. I renamed this folder to "blog." Next I uploaded the folder to my hosting service at Godaddy
Edit the web.config and siteSecurity.config according to the instructions on the website. You will also need to change the permissions on three folders logs, content, siteconfig to have read/write access.
I will discuss the web.config edits a little because it seems there is a bit of ambiguity on the web with how the trust should be set up.
The out of the box setup of the web.config trust elements:
<!-- <trust level="Medium" originUrl=".*" /> -->
<trust level="Full" originUrl="" />
I simply removed <trust level="Full" originUrl="" /> so all I had was the commented out <!-- <trust level="Medium" originUrl=".*" /> --> element. I have heard some talk to just remove <!-- <trust level="Medium" originUrl=".*" /> --> all together and others saying if you un-comment the element the blog should work. For Godaddy removing the one line and commenting out the other is what worked for me. I always like to leave configuration setting in the file and just comment them out. I will forget about them if I don't....I blame college.
- Adding Virtual Directories and Changing Settings
This is the part which slowed me down. You will need to not only create a virtual directory the same name as the folder that holds the content for your blog, in this example that directory is named "blog", but you will also have to create 3 sub virtual directories under the "blog" virtual directory on Godaddy called "logs," "content," and "siteconfig." Notice the virtual directories are the same name as the folders within the "blog" folder.
Next, you will need to change the settings on all four virtual directory folders to have "anonymous access" and "application root." Finally you will need to change IIS7 from integrated mode to classic mode. (Update: i've been told that if you use the web.config file that is meant for IIS7 integrated you will not have to make this change. For right now the standard package with dasblog is the web.config which requires you to use classic mode).
Once you have followed these steps and followed the steps provided by dasBlog you should be good to go on installing dasBlog on a hosting provider the hard way.
Some of the problems I ran into.
- The first error I was recived was a "HTTP Error 500 - Internal server
error." This error really tells you nothing and was quite frustrating. I eventually fixed the error by switching IIS7 to classic mode on godaddy.
- The second error I encountered was "System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission," This was due to the fact I did not have the 3 virtual directories set up under my "blog" virtual directory in IIS7.
Painless way
- Click "Your Applications" from the home screen of your "Hosting Control Center"
- Select "blogs" from the left hand menu
- Select "dasBlog" from the list of blogs
- Select "Install Now"
If by chance Godaddy states your hosting plan is not supported for this product. You have to have .net and IIS. If you have IIS7 make sure you have it on classic mode. Without classic mode, .net, and IIS, Godaddy tells you your hosting plan is not compatible.
|