I generally don't post on political topics, but this is a big one...
Today, as I'm sure it isn't news to you anymore, the House of
Representatives passed the Economic Stabilization Act of 2008
(H.R.1424), which includes $700 Billion to bailout the troubled financial institutions, plus aproximately $110 Billion in tax cuts.
Go read the bill or it's summary here: http://financialservices.house.gov/
When I started writing this post I had this long post explaining reasons of why
this bill is so bad. But, as I thought about it more, it became really clear that this solution just may work afterall.
I can thank the movie A Beautiful Mind (and more precisely John Nash and the Nash Equilibrium theory) for giving me the insight to this problem and solution. There is a scene in the movie where John and a few classmates are in a bar, and these girls walk in. One is a beautiful blonde and the others are just "average" girls. All the guys want to try for the blonde. But, then John has a revalation that if they all try for the blonde they will all ultimately fail. Once rejected by the blonde they will try for the others and get rejected as well, since no one likes to be second choice. But if they all go for the average girls, no one gets rejected and they all win. Or as they state in the movie, they "all get laid."
What's good for the individual isn't always good for the group. But, what's good for the group is generally good for the individual.
At first glance the bill doens't make sense. We are rewarding those that are failing, and paying for it from those that aren't. It's almost like the failures are winning and those that aren't failing become failures. But!...
If we apply the "Nash equilibrium" theory to this problem we get the following...
By bailing out the troubled financial intitutions we keep them from going bankrupt. And, by helping change the terms of people mortgages we keep them from getting foreclosed. By doing this week keep money flowing, and prevent the economy from crashing. Since we prevent it from crashing, everyone ultimately wins.
If we were to let them go bankrupt and foreclosed, which would be faire to do after all. All we would end up with is a failing economy in a downward spiral, and everyone would ultimately fail.
Pure Genius!!!
In the course of starting to write a rant and contemplating the failure of this bill, I've come full circle in the matter of minutes. Now, lets hope this is correct and this works.
Currently rated 2.0 by 4 people - Currently 2/5 Stars.
- 1
- 2
- 3
- 4
- 5
The voting for the winners of the Community Coding Contest has begun. Go Vote Now!
To vote, just go the the poll on the right hand side of the Community Coding Contest website and cast your vote.
You can also view a list of all contest entries here: http://communitycodingcontest.org/AllEntries.aspx
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Recently, I started working on a new open source project (you'll have to wait until the first release to find out what it is), and the goal of it is to play nicely with any JavaScript Library you want to use. That means it needs to work nicely with jQuery, prototype, ASP.NET AJAX and the such. This means that I need to grow all my own code for registering namespaces and using inheritence.
One major JavaScript feature that I needed a refresher on, and ultimately get figured out, is Prototypal Inheritence. Sounds fancy, right? Well, it's actually rather simple to do, but can be a little cryptic since there isn't much info out there that just shows you a really basic example of doing it. So, this is why I decided to write this post; to give a really simple example and explanation on JavaScript Prototypal Inheritence.
Basics of Prototypal Inheritence
First, here's the really simple code:
FirstClass = function() {
/// Constructor
this.test1 = "Chris";
};
FirstClass.prototype.GetTest1 = function() { return this.test1; };
SecondClass = function() {
/// Constructor
};
SecondClass.prototype = new FirstClass;
SecondClass.prototype.GetTest1 = function() { return "SecondClass: " + this.test1; };
First, we have the FirstClass object defined. In the constructor we are defining and setting the objects "test1" variable to "Chris". Then a "GetTest1" function is being defined using prototype that returns the value of the "test1" variable. Now, we have a simple objec that will return the test "Chris" when you execute the "GetTest1" method.
Here's an example of using the FirstClass object:
var a = new FirstClass();
alert(a.GetTest1());
Secondly, we have our SecondClass object, that also sets a variable named "test1" and implements a GetTest1 function. This object woud basically be the same, except we want to return a slightly modified string from "GetTest1" instead of returning what FirstClass returns. So, for this we need to use inheritence.
The key to prototypal inheritence is, the line that reads "SecondClass.prototype = new FirstClass". This basically takes a copy of FirstClass, constructor and prototype stuff, and sets SecondClass's prototype to that. Then after we do this, then we redefine the "GetTest1" method to be what we want it to be. And, now when we execute "GetTest1" it will return "SecondClass: Chris" instead of just "Chris".
Here's an example of using the SecondClass object:
var b = new SecondClass();
alert(b.GetTest1());
Now isn't that simple? I told you so.
Calling Base Object Methods
Now, one thing that you're probably used to (especially if you're used to .NET) is being able to access the Base objects version of the methods. In the example above that would be "GetTest1".
To do this, we need to grab a copy of the base objects "GetTest1" method within our SecondClass objects constructor. Then we can use this within our new "GetTest1" method.
Here's an example of doing this:
SecondClass = function() {
this.base_GetTest1 = FirstClass.prototype.GetTest1;
};
SecondClass.prototype = new FirstClass;
SecondClass.prototype.GetTest1 = function() { return "SecondClass: " + this.base_GetTest1(); };
Using this technique, you can easily copy any logic that the Base object used within the method and reuse it within our new method. This same technique can be used for copying methods over from other objects, not only the one that our object inherits, but if you do this you need to make sure any variables and methods it calls exist in your object.
Currently rated 5.0 by 1 people - Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5
There is only 1 day left to submit your entries for the Community
Coding Contest!! There are currently only 5 entries submitted, so your
chances are pretty good if you submit an entry today! The deadline to
submit entries is 12AM EST October 1st, 2008, that's less than 36 hours
away. And, then voting begins.
If you're not familiar with the contest, it's an awesome chance to win a Free MSDN Premium Subscription with Visual Studio 2008 Team Suite, plus a few other prizes!
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Today, "We" released a new updated version of the Virtual Earth JavaScript Intellisense Helper that is updated to support the brand new Virtual Earth v6.2. You can learn more about what's new in Virtual Earth v6.2 here: http://blogs.msdn.com/virtualearth/archive/2008/09/24/announcing-the-virtual-earth-web-service-and-virtual-earth-map-control-6-2.aspx
It appears that Mark beat me to blogging this release (which makes sense since he's the one that posted the final ZIP of the release): http://blogs.msdn.com/devkeydet/archive/2008/09/30/released-virtual-earth-javascript-intellisense-helper-for-6-2.aspx
And, Thanks for the props Mark!
In case you aren't familiar with what the "Virtual Earth JavaScript Intellisense Helper" is:
"The purpose of this project is to fully enable JavaScript Intellisense for the Virtual Earth Map Control inside of Visual Studio 2008.
Creating Microsoft Virtual Earth mashups and applications just got a whole lot easier. This JavaScript library enables Intellisense for the Microsoft Virtual Earth 6.2 (current release) AJAX control in Visual Studio 2008"

Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
I was just building something in Silverlight that makes use of the Isolated Storage, and I uncovered a bug in Silverlight 2 Beta 2 that cause's it to crash and you are unable to write to the Isolated Storage. So, I dug in and found the location on disk where Silverlight stores the files for Isolated Storage.
Here's the file location under Windows Vista where Silverlight stores the files for Isolated Storage:
C:\Users\{username}\AppData\LocalLow\Microsoft\Silverlight\is
Just replace the text "{username}" with the Windows Username of the user the data is stored for.
The bug that I ran into was also causing the Silverlight Configuration dialog (which pops up when you right click on Silverlight content within the browser) to crash when I selected the Application Storage tab. So, this bug prevented me from clearing the cache, and I wasn't able to get my app working again. I just deleted all the files within the above directory and if fixed my problem.
If I figure out what I did to cause the issue, I'll find the place to report the bug.
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Here are some of my thoughts on the Windows operating system and how thing could be improved in the "next" version after Vista. Also, the ideas aren't in any particular order of importance, they are just in the order I typed them in.
1) Make the Desktop version of Windows more Modular, like Windows Server 2008
Windows Server 2008 is more modular, you can install Server Core that doesn't even have a graphical interface, or you can install Windows Server 2008 with just the features you want/need. Why not make a Desktop version of the OS like that? Let the advanced users, during installation or from the Programs/Features Dialog, decide which features they want to install. Currently, Windows Vista Ultimate could be considered a little bloated, and the extra features installed that I don't use are just taking up space, and some run in memory affecting my system performance. For instance, If I don't want or use Windows Media Center, then don't install it, it's not required for Windows to run.
2) Improve Data CD/DVD Burning, make it usable
Since WinXP, we've had Data CD burning capabilities. It hasn't been the best functioning, and IMO is too slow to use. I actually use a Free burning program called Deep Burner to burn data discs, and its' performance is much faster. This is an area in Windows that needs improvement, and since the functionality is already baked into Windows, why not improve it to be the best it can be?
3) Add Mount ISO and Burn ISO Support
Developers and Sys Admins get ISO images from their MSDN subscriptions and elsewhere quite often, so why not make it easier on us by adding the capabilities to 1) Mount an ISO image to a Virtual Drive, and 2) Add support for burning ISO images to Disk. These features would make things much simpler, and such often used functionality should just be baked into the OS.
4) Add Blu-Ray Burning Support
Lets face it, our backup needs are growing in size. When I backup my data I need to use multiple writable DVD's to back everything up. Soon enough, Blu-Ray burners and media will drop in price enough to make them practical to use for backups. Since that will happen in the next couple years, why not add support for it to the OS?
5) Custom Themes and Visual Styles
It's nice to have a consistent look and feel for Windows, especially for branding. But, why not add customizability to Windows for users to design and use their own Visual Styles and Themes? It would make Windows more enjoyable to use, since you could change the look of it to match your personality and preference. Or, alternatively a bunch more (like 10 or more) Visual Styles could be baked into Windows for the users to choose from. This feature idea is all about personality.
6) Decouple Internet Explorer from the OS
It sure would be nice if you could have multiple versions of Internet Explorer installed on the same machine, at least from a developer/designer perspective. By decoupling IE from the OS, it would also enable you to uninstall Internet Explorer completely if you choose. Give a little more freedom to the user as to which web browser's they want to use and install.
This also goes along with the ability for full debugging of ASP.NET web applications within other non-IE browsers from Visual Studio, but this is really a seperate idea that's more a suggestion for the next version of Visual Studio.
7) Integrate Hyper-V into the Desktop Version of Windows
Virtualization is a technology that is not only valuable for Server Virtualization, but also for Desktop Virtualization for Developers. Yes, you can install Windows Server 2008 on your development machine and then use Hyper-V for virtualizing dev/test environments, but if you don't have an MSDN Subscription the Windows Server 2008 license can be expensive. Why not add Hyper-V to the Desktop Version of Windows, so developers can utilize it on their workstations and completely get rid of Virtual PC 2007?? Also, it sure would be nice to use Hyper-V on the same machine that I use Media Center on... After all, I use one pc for EVERYTHING!
8) Add Basic Virus Scanner
Let's face it, almost every pc has some kind of Virus scanner installed. Windows already has a Spyware scanner called Windows Defender. Being an advanced user and developer, I just don't get spyware on my machine, but the average user does. A worse thing that the average user also gets are Virus's, and they are much worse than Spyware. Why not add a new Virus scanning tool to the next version of Windows? After all, it will help make it an even more secure OS, right? One critical thing with this is, give the option to disable or completely uninstall the Virus scanner for those who want to use a different one, or none at all.
Here's a little secret, I haven't had a Virus scanner installed on my machine in over 2 years. I am very carefull about what I download/run, and have learned to be this way from getting burned over the years. I also do not download warez, which from my experience is the same as unprotected sex with a complete stranger. I have a second machine that I let anyone that comes over use, and it doesn't have a Virus scanner also, but I don't let anyone run as Administrator on that box either. I could argue that you don't need a virus scanner, but the truth is most user (the average computer user) does!
9) More Sidebar Plugins Baked into Windows
There need to be more Sidebar plugins baked into Windows. Yes, you can go online and download more, but why not have Windows come with more usefull ones? For example, I was initially surprised that Vista didn't come with Media Player or Live Messenger Sidebar Plugins.
10) Isn't it about time MS Paint gets an overhaul??
The functionality in MS Paint hasn't changed since Windows 95! There's a Free app called Paint.NET that is just plain awesome! Why not integrate a nicer image editing application into Windows?
UPDATED: 9-15-2008 - I added another feature idea to the list....
11) Be able to ReOrder Windows in the Taskbar by drag-and-dropIt
sure would be nice if you could reorder your task list in the Taskbar
by using drag-and-drop to change their order. The automatic ordering of
the windows/applications along with its automatic grouping by
application is a bit counter productive.
Ok, there's the first 10 things I could think of at the moment of how to improve Windows. If you have any other ideas, please post a comment, I'd be interesting in hearing them.
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
About two weeks ago I posted on how to Implement Custom Theme support in ASP.NET MVC. There were some breaking changes made when the Preview 5 release was released yesterday.
Here's a short list to a couple of the changes I had to make to my code from the previous post to get it working in ASP.NET MVC Preview 5:
- Delete WebFormThemeViewLocator - The contents of this object is now contained within the ViewEngine itself
- Delete WebFormThemeControllerFactory- This isn't needed anymore.
- Modify WebFormThemeViewEngine - Write a bunch of code that finds the appropriate View to use.
- Modify Global.asax - Remove code that adds the old ControllerFactory, and replace it with code that adds our newly improved WebFormThemeViewEngine
- Modify ControllerBase - Firstly, rename this to ThemeControllerBase since there is not a ControllerBase in System.Web.Mvc. Then, modify the code for the Execute method since it now takes in a RequestContext object as a parameter instead of a ControllerContext object.
Just for reference here's the code for the WebFormThemeViewEngine.
Download Code:
ASPNETMVC_Preview5_CustomThemeImplementation.zip (226.05 kb)
Below is the entire code for the WebFormThemeViewEngine, just for reference. If you are interested in looking at how I implemented this, just download and check out the entire code sample at the link above.
using System;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;
public class WebFormThemeViewEngine : System.Web.Mvc.WebFormViewEngine
{
public WebFormThemeViewEngine()
{
base.ViewLocationFormats = new string[] {
"~/Views/{2}/{1}/{0}.aspx",
"~/Views/{2}/{1}/{0}.ascx",
"~/Views/{2}/Shared/{0}.aspx",
"~/Views/{2}/Shared/{0}.ascx"
};
base.MasterLocationFormats = new string[] {
"~/Views/{2}/{1}/{0}.master",
"~/Views/{2}/Shared/{0}.master"
};
base.PartialViewLocationFormats = new string[] {
"~/Views/{2}/{1}/{0}.aspx",
"~/Views/{2}/{1}/{0}.ascx",
"~/Views/{2}/Shared/{0}.aspx",
"~/Views/{2}/Shared/{0}.ascx"
};
}
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName)
{
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
if (string.IsNullOrEmpty(viewName))
{
throw new ArgumentException("Value is required.", "viewName");
}
string themeName = this.GetThemeToUse(controllerContext);
string[] searchedViewLocations;
string[] searchedMasterLocations;
string controllerName = controllerContext.RouteData.GetRequiredString("controller");
string viewPath = this.GetPath(this.ViewLocationFormats, viewName, controllerName, themeName, out searchedViewLocations);
string masterPath = this.GetPath(this.MasterLocationFormats, viewName, controllerName, themeName, out searchedMasterLocations);
if (!(string.IsNullOrEmpty(viewPath)) && (!(masterPath == string.Empty) || string.IsNullOrEmpty(masterName)))
{
return new ViewEngineResult(this.CreateView(controllerContext, viewPath, masterPath));
}
return new ViewEngineResult(searchedViewLocations.Union<string>(searchedMasterLocations));
}
public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName)
{
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
if (string.IsNullOrEmpty(partialViewName))
{
throw new ArgumentException("Value is required.", partialViewName);
}
string themeName = this.GetThemeToUse(controllerContext);
string[] searchedLocations;
string controllerName = controllerContext.RouteData.GetRequiredString("controller");
string partialPath = this.GetPath(this.PartialViewLocationFormats, partialViewName, controllerName, themeName, out searchedLocations);
if (string.IsNullOrEmpty(partialPath))
{
return new ViewEngineResult(searchedLocations);
}
return new ViewEngineResult(this.CreatePartialView(controllerContext, partialPath));
}
private string GetThemeToUse(ControllerContext controllerContext)
{
string themeName = controllerContext.HttpContext.Items["themeName"] as string;
if (themeName == null) themeName = "Default";
return themeName;
}
private string GetPath(string[] locations, string viewName, string controllerName, string themeName, out string[] searchedLocations)
{
string path = null;
searchedLocations = new string[locations.Length];
for (int i = 0; i < locations.Length; i++)
{
path = string.Format(CultureInfo.InvariantCulture, locations[i], new object[] { viewName, controllerName, themeName });
if (this.VirtualPathProvider.FileExists(path))
{
searchedLocations = new string[0];
return path;
}
searchedLocations[i] = path;
}
return null;
}
}
Currently rated 3.5 by 2 people - Currently 3.5/5 Stars.
- 1
- 2
- 3
- 4
- 5
Update 9/16/2008: After too long, I finally tried uninstalling SP1 and reinstalling it and that fixed the issue. I'm glad it's fixed now! I haven't seen any other suggestions for fixing this, and I first tried repairing the installation, but only an uninstall and reinstall fixed it. Hope this helps solves anyone elses headache with this issue.
A few months ago (back in February actually) I blogged showing how to use the new DataContractJsonSerializer to serialize your .NET objects to JSON. Everything was fine until .NET 3.5 SP1 was released. It appears that the .NET 3.5 SP1 update breaks the DataContractJsonSerializer. Using the exact same code from my previous post that worked perfect on .NET 3.5 RTM, breaks with the following exceptions in .NET 3.5 SP1 RTM:
First Exception
This exception occurrs when running this code within a Console application:
System.MissingFieldException was unhandled
Message="Field not found: 'System.Runtime.Serialization.XmlObjectSerializerContext.serializerKnownDataContracts'."
Source="System.ServiceModel.Web"
StackTrace:
at System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson..ctor(DataContractJsonSerializer serializer, DataContract rootTypeDataContract)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject(Stream stream, Object graph)
at JsonSerializer_dotNet35SP1_IssueTest.JSONHelper.Serialize[T](T obj) in D:\TEST\JsonSerializer_dotNet35SP1_IssueTest\JsonSerializer_dotNet35SP1_IssueTest\Program.cs:line 56
at JsonSerializer_dotNet35SP1_IssueTest.Program.Main(String[] args) in D:\TEST\JsonSerializer_dotNet35SP1_IssueTest\JsonSerializer_dotNet35SP1_IssueTest\Program.cs:line 22
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Code for Console app:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
//using System.ServiceModel.Web;
namespace JsonSerializer_dotNet35SP1_IssueTest
{
public class Program
{
static void Main(string[] args)
{
/// Sample code using the above helper methods
/// to serialize and deserialize the Person object
Person myPerson = new Person("Chris", "Pietschmann", 26);
// Serialize
string json = JSONHelper.Serialize<Person>(myPerson);
// Deserialize
myPerson = JSONHelper.Deserialize<Person>(json);
}
}
[DataContract]
public class Person
{
public Person() { }
public Person(string firstname, string lastname, int age)
{
this.FirstName = firstname;
this.LastName = lastname;
this.Age = age;
}
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public int Age { get; set; }
}
public class JSONHelper
{
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer
= new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
return retVal;
}
public static T Deserialize<T>(string json)
{
T obj = Activator.CreateInstance<T>();
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer
= new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
obj = (T)serializer.ReadObject(ms);
ms.Close();
return obj;
}
}
}
Second Exception
This exception occurrs when running this code within an ASP.NET WebPage:
System.MissingMethodException was unhandled by user code
Message="Method not found: 'Boolean System.Runtime.Serialization.DataContract.get_IsReference()'."
Source="System.ServiceModel.Web"
StackTrace:
at System.Runtime.Serialization.Json.DataContractJsonSerializer.CheckIfTypeIsReference(DataContract dataContract)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.get_RootContract()
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject(Stream stream, Object graph)
at _Default.JSONHelper.Serialize[T](T obj) in d:\TEST\JsonSerializer_dotNet35SP1_IssueTest_ASPNET\Default.aspx.cs:line 55
at _Default.Page_Load(Object sender, EventArgs e) in d:\TEST\JsonSerializer_dotNet35SP1_IssueTest_ASPNET\Default.aspx.cs:line 22
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Code for ASP.NET app:
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/// Sample code using the above helper methods
/// to serialize and deserialize the Person object
Person myPerson = new Person("Chris", "Pietschmann", 26);
// Serialize
string json = JSONHelper.Serialize<Person>(myPerson);
// Deserialize
myPerson = JSONHelper.Deserialize<Person>(json);
}
[DataContract]
public class Person
{
public Person() { }
public Person(string firstname, string lastname, int age)
{
this.FirstName = firstname;
this.LastName = lastname;
this.Age = age;
}
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public int Age { get; set; }
}
public class JSONHelper
{
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
return retVal;
}
public static T Deserialize<T>(string json)
{
T obj = Activator.CreateInstance<T>();
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
obj = (T)serializer.ReadObject(ms);
ms.Close();
return obj;
}
}
}
WTF??
I searched for a possible solution, but the only thing I found was this link (http://forums.msdn.microsoft.com/en-US/csharpgeneral/thread/37558154-88a9-41f0-a9d6-a2cb4052a5ce/) where someone mentions the First Exception above. The suggested solution was to use the KnownType Attribute on the object, but that doesn't help with my above code.
Does anyone know a work around for this that doesn't involve using the older JavaScriptSerializer object?
Well, for now, it looks like I'm almost the only one to experience this issue.
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
I just listened to the latest episode of FLOSS Weekly; episode 36 on CouchDB. This episode is an interview with Jan Lehnardt about CouchBD.
Here's a description of what CouchDB is from their website:
Apache CouchDB is a distributed, fault-tolerant and schema-free
document-oriented database accessible via a RESTful HTTP/JSON API. Among other
features, it provides robust, incremental replication with bi-directional
conflict detection and resolution, and is queryable and indexable using a
table-oriented view engine with JavaScript acting as the default view
definition language.
CouchDB is written in Erlang, but can be easily accessed from any
environment that provides means to make HTTP requests. There are a multitude of
third-party client libraries that make this even easier for a variety of
programming languages and environments.
I haven't installed or tested it out, but it looks like a really cool idea for a small efficient database design. I always find it interesting to hear about some of these cool "new" projects that look at everyday problems in new and different ways.
Be the first to rate this post - Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
|