Discovering .NET

Here I will post problems I and my colleagues met and solutions we found.

Monday, November 16, 2009

ReportViewer control from Microsoft

Recently we needed to add reporting capabilities to our web site. We had following requirements

  • All standard requirements for report designs, they are pretty much the same everywhere.
  • Ability to share report designs between web and desktop applications.
  • Export to PDF and Excel.
  • Royalty free.

We decided to try Microsoft Report Viewer control from VS 2008. And we started with web. Also, we have our "Data Access layer" which produces data as lists of objects, no direct access to the database. There is some logic involved in building these data both in database and in .NET.

You can find what report viewer control can and cannot do anywhere, what surprised me is the way it's done.

First of all, we didn't use Reporting Service, we used LocalReport.

  1. LocalReport uses a lot of memory. To give you an idea, we used set of data with about 50,000 records. It took about 16Mb of memory for the data and then it took about 200Mb to prepare report in PDF. It was much worse for Excel, 500Mb. We tried to add/remove sorting from rdlc template - 100Mb difference. This was exporting reports without using ReportViewer control itself.
  2. Then we tried to use ReportViewer web control. The problem here was that it uses about same amount of memory from sessions. OK, it doesn't make much sense to prepare such reports in "on-demand" mode. Still it took about 20Mb for 3000 records. This is just terrible
  3. Not only control uses session, it leaves objects in session when rendering is done and we clear the list of data sources.
  4. Export to Excel is supported for Office 2003, not 2007
  5. Not an issue, but everything is copied in two namespaces, WinForms and Web. Why not to reuse LocalReport?

So, what we are going to do next? First of all we are going to try to use Reporting Services. I expect it to be little bit tricky since we still don't want to use direct access to the database, but use our Data Access layer, but it seams doable. When using Reporting Services ReportViewer control supposed to be able to work without using session.

Second, we will break batch reports into multiple files. Having grouping and sorting in mind, this two will require some additional efforts.

I will report how this is going.

Wednesday, November 11, 2009

Changes in the direction of this blog.

I didn't post for a long time. One of the reasons for that is that I became less of a programmer and more of... I would like to call it an application architect.

Different people may define "architect" differently, nevertheless, the point is that I may have more thoughts about development of software, which I want to put in writing. So, there will be some "offtopic" posts.

Wednesday, June 24, 2009

This element is not currently associated with any context

When debugging WCF you can see this exception. Some people advice to just disable stop on exception But it's useful feature.

The better is to go into details of this dialog and disable just this specific exception. The only small problem is that it's not in the list. But it's really a small problem. You can add it.

Just press "Add..." button, choose "Common Language Runtime Exceptions" from the drop down list and type the exception type, which is System.Configuration.ConfigurationErrorsException. Now you can disable stopping on just this exception and not all of them.

Friday, June 05, 2009

Getting output parameters when executing reader in ADO.NET

Interestingly, the values of output parameters are not available after ExcecuteReader() is called, even after all records were fetched.

To get these values it is required to either close reader (call reader.Close()) or at least call NextResult() method.

Wednesday, June 03, 2009

WCF - nullable values are not working in generics

Today I spent couple of hours figuring out why I suddenly got an error "Referenced type 'x`1, ... with data contract name 'xIF_Ph6aZR' in namespace 'x cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types."

It was working and what I did just little bit of re-factoring. What I found is that there is a combination of conditions that does not work, while every one of them works separately:

  1. Generic class is used as DataContract.
  2. This class has nullable DataMember property
  3. You want to reference your class in your client instead of creating in through wsdl.

[DataContract]
public class DummnyContract<T> where T: IBusinessObject
{

[DataMember]
public DateTime? LastModified{get;set;}

}
and then you use it like this:


[ServiceContract]
public interface IService
{
[OperationContract]
DummyContract<int> Get(int id);

}

This just does not work when you reference your assembly with declaration of this class. You can have it without class being generic. Or, you can have generic without nullable property. But not together.

Saturday, May 02, 2009

WSE and Visual Studio 2008

If you got here from search engine you already know that WSE is integrated into Visual Studio 2005, but not 2008. You also know that if add reference to the web service that implements WSE you would get proper class in Visual Studio 2005 but not in 2008. The common advise is use VS 2005 to do the import, or use svcutil.exe.

The easiest solution though is just to open Reference.cs file and replace System.Web.Services.Protocols.SoapHttpClientProtocol with Microsoft.Web.Services3.WebServicesClientProtocol manually.

Also, here you can find how to make plug-in available in VS 2008 UI.

Friday, April 24, 2009

WCF under IIS access problems

Today I spent few hours trying to resolve problem with our WCF server for one of our clients. Somehow everything went wrong. Our configuration is WCF server that utilize .NET 3.5, and I set it up to work under IIS6.

The errors I got were different, but in result it was all about setting permissions for IIS. Many of them were trivial, but the last one I found tricky. HTTP result code was 500, internal server error, the error in EventViewer said: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxx or one of its dependencies. Access denied.

Logically, something was wrong with access to \WINDOWS\Microsoft.NET\Framework\v2.0.0.527 folder. However, it was not so. What helped me was adding NT permissions to the folder with my WCF server to the group IIS_WPG. And this is after I tried to add permissions to user ASP_NET… and IUSR_… without success.