Posts

Showing posts with the label .NET FRAMEWORK

Get File Length over http before you download it

This is one of those forum questions that you “think” you know the answer to, and then you’re proven wrong. User wants to download a file from a remote site but they do not want to proceed with the download if the file is larger than 10MB. Make sense, right? I said there was no way to do this without downloading the file. I was wrong. Here’s how he solved his own problem: static void Main(string[] args) { string completeUrl = "http://www.eggheadcafe.com/FileUpload/1145921998_ObjectDumper.zip"; WebClient obj = new WebClient(); Stream s = obj.OpenRead(completeUrl); Console.WriteLine( obj.ResponseHeaders["Content-Length"].ToString()); s.Close(); obj = null; Console.ReadLine(); } The above correctly reports the file size of 85,827 bytes without ever downloading the file! Somebody had a problem. Instead of giving up (or worse, taking my so-called “expert advice”) he thought  “outside the box” and found a solution. I call that outstanding! NOTE: At least one comm...

Silverlight 2 Beta 2 Installation Issues

Image
The "bottom line" (you can read all the gory details after this): 1) I DO NOT recommend installing Visual Studio 2008 SP1 Beta and / or .NET Framework 3.5 SP1. There are simply too many issues and fragile fixes. Just wait until all this stuff gets fixed and save yourself a lot of headaches and lost time. 2) I DO recommend installing Silverlight 2 Beta 2, the Tools, the documentation, and Blend June 2008 Preview. Just be very careful about the ServiceProxy assembly issue mentioned at the end of this post, as it seems to be able to occur whether or not you choose to try the Service Pack route. Well, 2 out of 3 ain’t so bad! I got SL2B2, the Visual Studio Tools and Blend June Preview on 2 out of 3 PCs and everything is working beautifully. On the third PC (the one at the office, which of course had to wait until Monday June 9, unless you stayed very late Friday night) however, I ran into the below issue: Method 'SelectSilverlightProject' in type 'Microsoft.VisuaS...

ASP.NET "App_Data": Writing files vs Application Restarts

Most ASP.NET developers know that if you create a new file , modify any file in the application root or the /bin folder, or modify web.config, this will trigger an application restart. InProc Session, Application and Cache state go bye-bye. This is a major cause of "WTF" type newsgroup and forum posts by n00b developers who don't yet fully understand the ASP.NET runtime model and its rather complicated set of behaviors - which are by design. However, there is a special folder, APP_DATA, that is designed not to respond to this filesystemwatcher behavior. In a WebSite application this folder is created by default. It is normally used for SQL Server MDF database files using the UserInstance SQLEXPRESS hosting mechanism, or for XML files. The good thing to know is that this works the same way (filesystemwatcher events are ignored by the ASP.NET runtime) for Web Application Projects . The only difference is that with a WAP you need to create the folder manually (except with VS...

Silverlight 2.0: Cross-Domain Access Redux

Scott Guthrie has been publishing some "pre release" very cool blog posts about the upcoming Silverlight 2.0 release. One of the most interesting features is that cross-domain access will be allowed (think JSONp and Crockford's JSONRequest or other cool ideas). Here's a short quote: Cross Domain Network Access Silverlight 2 applications can always call back to their "origin" server when making network calls (meaning they can call URLs on the same domain that the application was downloaded from). Silverlight 2 applications can also optionally make cross-domain network calls (meaning they can call URLs on different domains from where the application was downloaded from) when the remote web server has an XML policy file in place that indicates that clients are allowed to make these cross-domain calls. Silverlight 2 defines an XML policy file format that allows server administrators to precisely control what access a client should have. Silverlight 2 also honors...

FileSystemWatcher Events and incomplete file errors

This is a question that has popped up numerous times, and I myself have had to deal with it: You get a FileSystemWatcher event that a new file was created in a folder you are monitoring. So you try to process the file, but problems arise because the process that has written the file isn't finished writing it yet. One way to handle this is to have the process that is writing the file send a second small text file consisting of something like the name of the file just written and the datetime that it was completed. You would get an event that this new file had been written, and your code logic would tell you what to do at this point. Of course, this assumes that you have sufficient control over the file - writing process to make this change. One newsgroup poster commented, "We're running a windows service which contains several filesystemwatchers. Sometimes we hit spikes of 20-50.000 files in a matter of seconds and each file can potentially take some time to process. The...

Entityize and ASCIIfy your XML text strings

2 is not equal to 3, not even for very large values of 2 -- Grabel's Law I have a custom search facility that I use on a couple of different web sites where the search queries are stored in a database table in order to compute count statistics and also to generate a standard xml sitemap for the search engines to nibble on. Problem is, I don't know what users are going to enter as search terms. From a purely search standpoint, I really don't care; if they enter gobbledegook Unicode glop and get back no search results, fie on them, right? However, I need to clean this stuff before I store it in the database since when I pull it out to generate my custom sitemap, I'm going to end up with illegal XML characters in the sitemap document. That means google, ask.com, live.com and yahoo are all going to choke on it and I might as well not even have a sitemap if that happens. So I put a couple of static cleanup methods into global.asax which conveniently allows them to be cal...

MSDN Code Gallery Goes Live

“Don't piss on my leg and tell me it's raining.” -- Judge Judy The new MSDN Code Gallery has gone live (although at the time of this original post it wasn't fully functional, e.g. I could not sign in or create a new resource, but as of now it seems to be OK). My take on this is that this is Microsoft's replacement for the User Samples section on the old Gotdotnet.com site. I hope it gears up, there are already some very nice code samples there. We will see what happens. You can download official Microsoft code samples, download user-submitted code, access tutorials and create your own "resource" page to upload your code samples or other offerings. I guess I'll have to read through the Terms of Service once this thing "really" goes live and all of it is working. Whereas Codeplex.com offers source control for real "projects" with multideveloper support, the idea of Code Gallery is to provide a simpler interface for the average develop...

.Net Links of the Day: Class Builder Wizard, OpenID. Visual WebGui and Patent Extortion

The most radical revolutionary will become a conservative the day after the revolution. - Hannah Arendt CODEPLEX: Class Builder Wizard is a Microsoft Visual Studio wizard that generates data object classes and a full data layer implementation for Microsoft SQL Server database objects. It can also be used to quickly create custom classes (not necessarily based on a database object) by defining the structure of the class "manually." And, it works with Visual Studio 2008! If you've gotten frustrated waiting for updates to the Repository Factory and other GAT-based add-ins, then this is for you. It's simple, elegant and it gives you all the "DAL" code you need for your deal to work! All you do is "Add Item" and choose the template and follow the "Way of the Wizard"! It even generates a .SQL file with all the T-SQL Code to get your database in synch with the generated DAL code. OPENID: I've UnBlogged about OpenID before , intimating tha...

.NET Framework Source Code Debugging is Live

Illegal aliens have always been a problem in the United States. Ask any Indian. - Robert Orben This was trumpeted several months ago mostly by Scott Guthrie, and now it is live (although not all sources and symbol files are available at present). None of this is rocket science, it's already built into Visual Studio. However, up until now there were no symbol files and sources for the BCL and related assemblies. Now there are. This is, in my opinion, not only a great debugging tool for any developer who is interested in "getting under the hood", but it is also a great learning tool. If you are not sure you understand what I'm talking about, just go ahead and "do it". The easiest way to get started with this is to follow the instructions on Shawn Burke's blog post here . Be sure to follow the instructions exactly - they are not difficult. It requires the download of a QFE to set up the debugger properly, the url is specified in Burke's post. There is...

Visual Studio: Difference between Build and Rebuild

Believe it or not, I was never sure about this until this morning when another dev and I were discussing it. So, I searched the web and found the answer: Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean. Build or Rebuild Solution builds or rebuilds all projects in the your solution, while Build or Rebuild <project name> builds or rebuilds the StartUp project. To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. The project name now appears in bold. Compile just compiles the source file currently being edited. Useful to quickly check for errors when the r...

The ASP.NET 3.5 Extensions Preview --MVC, Entity Framework, ADO.NET Data Services +

"If I Dispose the Car, will my delegate references be garage collected?" -- newsgroup poster This provides new functionality to ASP.NET 3.5 and ADO.NET in 2008. The new features target MVC, Entity Framework, ADO.NET Data Services and dynamic data Supporting Test Driven Development - including a powerful and extensible MVC framework. Creating the best server for Rich Clients - including Ajax history support and Silverlight controls for ASP.NET. The Readme is here . The download of ASP.NET 3.5 Extensions Preview is here . I did some early work with the Entity Framework and liked what I saw. Don't you just love those little installer messages, "The installation is taking longer than expected . . ."? And More Cool Stuff A couple of other items you might be interested in (at least, that I am interested in): 1) The FeedSync API. Formerly Ray Ozzie's "Simple Sharing Extensions". The easiest way to get into this is to download and play with the codeplex s...

Umm, Did you search first?

"There is no shame in stating the obvious, as it may not actually be obvious to others." -- Me Newsgroups and forums are littered with well-intentioned but often moronic posts asking questions that could be easily answered - in a majority of cases - by simply typing the relevant search term into the Google search textbox and pressing the "SEARCH" button. Often these same posts are cluttered with replies from equally lazy people who offer opinions, advice and such --and who have not bothered to search either! A case in point: User posts a somewhat sarcastic item asking if there is an easy way to use Oracle for Session state, intimating that "not everybody uses SQL server". There are three replies, all of them more or less useless, because they didn't offer a real answer - which could easily have been determined with a 30 second search! So I did the search: http://www.google.com/search?q=ASP.NET+ORACLE+Session+provider Not exactly rocket science! And rig...

New .NET Service Packs Available

Microsoft .NET Framework 2.0 Service Pack 1 (x86): http://www.microsoft.com/downloads/details.aspx?FamilyID=79bc3b77-e02c-4ad3-aacf-a7633f706ba5&DisplayLang=en Microsoft .NET Framework 2.0 Service Pack 1 (x64): http://www.microsoft.com/downloads/details.aspx?FamilyID=029196ed-04eb-471e-8a99-3c61d19a4c5a&DisplayLang=en Note that the 2.0 Service Pack is actually a full Framework install. If you uninstall .NET 2.0 SP1 (even if you had .NET 2.0 installed beforehand) the whole .NET Framework is removed. It does NOT revert you back to .NET 2.0 RTM. Microsoft .NET Framework 3.0 Service Pack 1: http://www.microsoft.com/downloads/details.aspx?FamilyID=ec2ca85d-b255-4425-9e65-1e88a0bdb72a&DisplayLang=en When you install the .NET Framework 3.5, these service packs are required prerequisites and are installed automatically; these are available as separate downloads for those who aren't ready to deploy .NET Framework 3.5. If you are installing Visual Studio 2008, you don't ne...

How to store a date in 4 bytes?

"My Karma ran over your dogma." - Unknown This was an interesting little C# newsgroup nugget. User has a registration code with 4 unused bytes, and wants to know how to store a date in same. (Actually I believe the user was thinking of 4 extra characters in a string - not "bytes", but the exercise is still a good one). Suggestions were made to store an integer representing the number of days from a fixed date. That would certainly do it, but it doesn't convey any context. Here's my take: using System; using System.Collections.Generic; using System.Text; namespace _bytedate { class Program { static void Main(string[] args) { // this makes sorting by date on an integer value perfect, // e.g. year+month+day, padded to make an integer int myDate = 20071105; byte[] b = BitConverter.GetBytes(myDate); Console.WriteLine(b.Length.ToString() + " bytes."); // reads "4 bytes" // And -back again: Console.WriteLine("Original: " +BitConverter...

Incompatibilities between Framework 2.0 and 3.0 versions on Vista vs XP

The human mind treats a new idea the same way the body treats a strange protein; it rejects it. - PB Medawar Hans Passant, an MVP and moderator of one of the MSDN Forums, found some interesting items: The .NET 3.0 version of the framework as installed on Vista is not the same as the one installed on XP SP2. On Vista, the setup utility overwrites all the V2.0 assemblies and upgrades them from version 2.0.50727.42 to 2.0.50727.312. There are some differences between the 42 and the 312 revisions of mscorlib.dll and System.dll. There are indeed a few places where 312 explicitly checks for Vista . There are several places where a SecurityPermission attribute is changed from InheritanceDemand to LinkDemand. And what looks like bug fixes in PerformanceCounter, FileWebRequest, RuntimeMethodInfo and UdpClient. Hans says that WaitHandle is the most visible class with new exceptions being thrown. There's also a potentially breaking change in HttpServerUtility that was discovered by Juan Llibr...

KB929729 Windows Update Failure - An Easy FIX

Image
OK, it's Microsoft Windows Update "Fun Time" again! KB929729 Security Update for .NET 1.1 shows up in Windows Update and guess what? It never goes away. It's like it's going to be there wanting to get reinstalled like FOREVER. The 1.1 service pack was an optional update that many users did not install, so the latest security update is doomed to fail. The security update did not search for the right version prior to installation so either you got a installation failure message or it "updated sucessfully" only to reappear as a needed update a few minutes later. If you are unfortunate enough to have .Net Framework version 2 or 3 without updating your service pack for version 1 your headaches just got worse, because the official "FIX" for this involves uninstalling ALL versions of .NET Framework and is quite painful. Fortunately for many the shorter "Fix" I detail here should work. NOTE: This is for Windows VISTA ONLY. 1) Instead of using...