Tuesday, March 22, 2011

Just another illegal access to loading collection EXCEPTION

There are many reasons for this exception to pop up especially if you are using the Lazy initialization feature of NHibernate.

I had simple bi-directionally mapped one to many relationship (Error - Error Details). Nhibernate was not throwing any exceptions during the loading of a List of Errors, but WCF was complaining about a type mismatch when trying to serialize the list of Errors. [Note. I have reference preserving custom datacontract serializer implemented that works fine.]

This made me look into the actual list which WCF is trying to serialize, then only i noticed that the Error Details collection was full of this "illegal access...." exception.

couple of hours of googling brought me nothing as various articles suggested, setting inverse true, setting access attribute, orphaned records in the database etc. where none of these was the reason for mine, but please note that these can also be the cause for this exception so do not rule them out.

Finally mine was due to a type mis -match in the Error Details mapping, in the hbm file, so if none of the above solves your problem take a second look at you hbm file mappings that can be the culprit in your case.

Monday, March 7, 2011

Cannot open backup device 'filename'. Operating system error 5/3

This Error kept me occupied for the most of the day yesterday, as i was trying to create a job Manager which automatically backs up SQL server db(s) on a given server with SMO objects. (well yeah. :o) its not the only thing it does).

Anyways As the message says the backup operation failed. First i was getting the Message with Operating system ERROR 5. I was running the C# program with a windows account, with Full privileges to run backup jobs on the SQL server, but still the back up JOb failed. The reason behind this is that no matter what the account that i use to run the code. It uses the system account under which the SQL server service runs to perform the backup operations.

Two things, you can either give permissions to the system account to perform backup operations and full access to the backup location, or can make the service hosted under a account with sufficient backup privileges and permissions to the backup locations.
But my problems were still there and was getting the same annoying ERROR over and over, it took me almost half an hour to notice that this time the number has changed from OS error 5 to 3.

Then it was a matter of seconds for google to get me difference between codes 3 and 5. 3 was to say that it "cannot find the path specified", and 5 meant "Access Denied". There was a spelling mistake in the path given, and after fixing that it was all good. Why can they include that little piece of information in the ERROR message ??

Tuesday, September 28, 2010

The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception.

The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception.

Today most of my time was spent around the Exception figuring out what made this error to be thrown by nhibernate. It was weird as the application was compiling without any warnings or Errors, and, was running without any problems till it tried to access the database.
Exception thrown was not helpful at all as it said “object reference not set….. “And there weren’t any inner exceptions as well.

Therefore the exception handling in the application was improved by including the Build session factory method in side an exception block. When the error was logged it said “The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception”. The next question was how come ? as my code never accessed the LinFu proxy factory directly and it was part of the nhibernates business to do so.

In fact the problem for me was that as the proxy is being loaded dynamically, Visual Studio does not copy all the dependencies properly to the bin dir. or bin\debug dir.
Simply I had to manually copy the nhibernate dependencies to the bin folder. This fixed the problem, though it’s weird that the LinFu Proxy is not copied to the bin folder even though there is a reference from my Data Layer.

Sunday, September 26, 2010

The referenced assembly "some.dll" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=

The referenced assembly "some.dll" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

This annoying exception tormented me for almost a day, while I was developing and WPF - nhibernate application using VS 2010.

By the way the error had nothing to do with either nhibernate or WPF. As I found out this was due to the more compact version of the .NET framework (client profile) introduced with VS2010.

Resolution – By Default the desktop client applications like Windows Forms and WPF applications) targets .NET Framework (Client profile) as client profile is just a subset of the .NET framework introduced to improve the deployment experience. Therefore re-target your applications to Full .NET framework instead of the compact framework to get rid of the Error. As you can see the error pops up only when you refernce assemblies like System.Web, System.Data.OracleClient etc. which are not part of the Compact framework.

There is a good article on the two Frameworks here: http://blogs.msdn.com/b/jgoldb/archive/2009/10/19/what-s-new-in-net-framework-4-client-profile-beta-2.aspx

Sunday, March 21, 2010

[Prevent saving changes] SQL Server/Express 2008

Saving changes is not Permitted. The Changes you have made require the following tables to be dropped or re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.

This is an annoying message that is prompted when trying to make changes to a table in SQL Server 2008/Express. While there can be many valid reasons for having this option [Prevent saving changes] switched on by default you would prefer to have this switched off during the implementation phase of the project.
Steps to disable the option [Prevent saving changes]

  1. Click on the Tools menu
  2. Click on Options of the Management Studio
  3. Click on the “Designers” tree
  4. Click on “Table and Database Designers”
  5. Uncheck “Prevent saving changes that require table-creation”
  6. Click “Ok”

Thursday, March 11, 2010

HTTP could not register URL http://+:8000/.

When i was trying to execute a WCF application created using a previos version of Windows (XP) came across the following error.

HTTP could not register URL http://+:8000/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details)

You can expect this error when trying to run a WCF service with an HTTP binding on windows VISTA. As you may have already noticed the culprit is the new Vista security settings. Usually the Visual Studio runs under the logged in user account which may not have sufficient priviledges to listen at a particular http address.

Find the solution here - http://blogs.msdn.com/amitlale/archive/2007/01/29/addressaccessdeniedexception-cause-and-solution.aspx

Onething missing in the solutions was how to run the command prompt as the administrator.Type "command Prompt" - in the start search box, then the command prompt would appear in the search results list, right click an say run as administrator.

But you can avoid all this hassel by running the VS studio as the administrator. :o) have fun!!

Sunday, February 28, 2010