Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention'

Topics: Data Access Application Block
Jan 11, 2011 at 9:23 PM

I've created a master form in VS 2010 C# 4.0 and then other forms are inherited from it. The master form access a SQL Database via DAB.

I can open the master form in the VS 2010 IDE without any problem. But when I try to open one the inherited forms, the following error occurs twice. I just click ok and everything works just fine.

But the error is there and I am worried that something is wrong.

Error shown (see attached image):

GlobalVars: GetUserPrivilegeLevel
Unable to cast object of type 'Microsoft.Practices.EnterpriseLibr​ary.Validation.Configuration.Unity.​ValidationBlockExtension' to type 'Microsoft.Practices.Unity.UnityCon​tainerExtension'.

By the first phrase in the error message, the error is happening in the following method that resides in a separated library:

public Int32 GetUserPrivelegeLevel()
{
var result = 0;

try
{
// Create the Database object, using the default database service. The
// default database service is determined through configuration.

#region SP parameters

// @guidUsuárioID UNIQUEIDENTIFIER,
// @intNível INT = NULL OUTPUT

#endregion

var db = DatabaseFactory.CreateDatabase();

using (var cmd = db.GetStoredProcCommand("usp_Suppor​t_GetUserPrivilegeLevel"))
{
db.AddInParameter(cmd, "@guidUsuárioID", DbType.Guid, UserID);
db.AddOutParameter(cmd, "@intNível", DbType.Int32, 1);

// No results will be returned
db.ExecuteNonQuery(cmd);

result = Convert.ToInt32(db.GetParameterValu​e(cmd, "@intNível").ToString());
}

// Connection was closed by ExecuteNonQuery method call
}
catch (Exception ex)
{
ShowErrorMessage("globalVars: GetUserPrivelegeLevel", ex);
}

return result;
}

And the error is happening during IDE design time execution.

What can be done to find out what is wrong and correct it?

Thanks in advance,

Eduardo Quintana

Jan 11, 2011 at 11:38 PM

I'm not sure what's causing the error.  It seems there's something wrong in your config.  Can you repro this on a small project and send it to me so I could investigate it?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 12, 2011 at 1:00 AM
Dear Sarah,

I've created the attached simple solution to demonstrate the problem.

Simply open solution in VS 2010, and try opening the form 'frmInherited.cs' in the IDE.

The error window will pop-up:

image

Note that I use Window 7 64 Ultimate and VS 2010 SP1.

Thanks for your support.

Eduardo Quintana
Development Director
SFTWY CDI Ltda.
Microsoft Partner
www.softwyse.com
5511-5686-6226 / 5511-3578-1689 / 5511-8317-9947

From: [email removed]
Sent: Tuesday, January 11, 2011 10:38 PM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

I'm not sure what's causing the error. It seems there's something wrong in your config. Can you repro this on a small project and send it to me so I could investigate it?

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 12, 2011 at 1:28 AM

Did you send it to entlib.support@avanade.com?  I haven't got your email with the attachment yet.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 12, 2011 at 9:38 AM
Dear Sarah,
I tried, but your email server has blocked the attached zip file.
Do you have any other email to which I could send the zip file?
Best regards,
Eduardo Quintana
From: [email removed]
Sent: Wednesday, January 12, 2011 12:28 AM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

Did you send it to entlib.support@avanade.com? I haven't got your email with the attachment yet.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 12, 2011 at 11:48 PM

Could you upload it in Windows Live Skydrive?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 13, 2011 at 10:28 AM
Dear Sarah,
I’ve send it via YouSendIt.
You should receive an email soon.
Please let me know if you do not receive it today.

Best regards,

Eduardo Quintana
SFTWY CDI Ltda.
Microsoft Partner
www.softwyse.com
5511-5686-6226 / 5511-3578-1689 / 5511-8317-9947
From: [email removed]
Sent: Wednesday, January 12, 2011 10:48 PM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

Could you upload it in Windows Live Skydrive?

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 13, 2011 at 1:13 PM

I was able to download the file but there were a lot of compile errors due to missing DevExpress references.  I tried commenting codes which requires references to it but I'm unable to remove the last 2 errors regarding an invalid resx file ( which is weird since there's no resx file included in the solution).  could you send a smaller repro?  You also mentioned you're opening a master form and inherited forms, I was actually expecting the form to be a windows/web form but the one I downloaded only has .cs file and no actual user interface.  Are those what you're actually refering to?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 13, 2011 at 3:00 PM
Dear Sarah,
I may have made a mistake when compressing the file.
It was supposed to be a complete solution.
About the DevExpress components, you could download and install a free trial copy of the suite from their site to look at the sample I will resend you. After the test you could simply remove the suite.
There is no need to recompile the solution, althrough it compiles ok, but does not run.
To get the error screen all you have to do is try opening the ‘frmInherited’ form.
I’ve resent you the sample, via YouSendIt.
Sorry for all the trouble I am giving you, but this type of error in the development environment is somenthing I never saw before.
Eduardo Quintana
From: [email removed]
Sent: Thursday, January 13, 2011 12:14 PM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

I was able to download the file but there were a lot of compile errors due to missing DevExpress references. I tried commenting codes which requires references to it but I'm unable to remove the last 2 errors regarding an invalid resx file ( which is weird since there's no resx file included in the solution). could you send a smaller repro? You also mentioned you're opening a master form and inherited forms, I was actually expecting the form to be a windows/web form but the one I downloaded only has .cs file and no actual user interface. Are those what you're actually refering to?

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 13, 2011 at 11:05 PM

I didn't receive a new email with the link to your updated sample.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 15, 2011 at 11:13 AM
Dear Sarah,
I’ve sent the file again, using the YouSendIt service:
image
Please let me know if you do not receive it soon.
Best regards,
Eduardo Quintana
Development Director
SFTWY CDI Ltda.
Microsoft Partner
5511-5686-6226 / 5511-3578-1689 / 5511-8317-9947
From: [email removed]
Sent: Thursday, January 13, 2011 10:05 PM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

I didn't receive a new email with the link to your updated sample.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 12:44 AM

I found a solution to the issue you're encountering.  You have a call to DatabaseFactory.CreateDatabase() but you don't have a default database connection string defined in your configuration file.  Add a connection string to your app.config file and make sure to set it as the Default Database of the Database Settings.  In xml configuration, it would look something like this:

<dataConfiguration defaultDatabase="MyConnectionString" />
<connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=(local);Initial Catalog=MyDb;Integrated Security=true"
        providerName="System.Data.SqlClient" />
</connectionStrings>

The error message was misleading though and I have no idea as to why it would show that, I have no knowledge on the DevExpress software.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 9:52 AM
Dear Sarah,
Thanks for you support.
Unfortunately, this is not the source of the error message
All programs in which this error occurs have the database connection, otherwise they would not work.
The sample project I sent you did not include this file for I know that it does not make any difference if it is there or not. The error will show anyway.
The original program from which I extracted the sample I sent you has the followint connection in the app.config file:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SBM.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<dataConfiguration defaultDatabase="SBMDataAccess" />
<connectionStrings>
<add name="SBMDataAccess" connectionString="Data Source=(local);Initial Catalog=SBM;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
...
Best regards,
Eduardo Quintana
Development Director
SFTWY CDI Ltda.
5511-5686-6226 / 5511-3578-1689 / 5511-8317-9947
From: [email removed]
Sent: Sunday, January 16, 2011 11:44 PM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

I found a solution to the issue you're encountering. You have a call to DatabaseFactory.CreateDatabase() but you don't have a default database connection string defined in your configuration file. Add a connection string to your app.config file and make sure to set it as the Default Database of the Database Settings. In xml configuration, it would look something like this:

<dataConfiguration defaultDatabase="MyConnectionString" />
<connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=(local);Initial Catalog=MyDb;Integrated Security=true"
        providerName="System.Data.SqlClient" />
</connectionStrings>

The error message was misleading though and I have no idea as to why it would show that, I have no knowledge on the DevExpress software.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 9:56 AM

That fixes the problem on my end.  Where is your app.config defined?  Is it on a class library or on the host/executable project?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 10:00 AM
Dear Sarah,
It is in the host executable program. Do you think it should be in the class library?
Eduardo Quintana
From: [email removed]
Sent: Monday, January 17, 2011 8:56 AM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

That fixes the problem on my end. Where is your app.config defined? Is it on a class library or on the host/executable project?

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 10:16 AM
Edited Jan 17, 2011 at 10:18 AM

No, it should really be in the host project.  I don't understand why it won't work for you.  Could you send me another repro including the app.config file?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 10:22 AM
Dear Sarah,
I will do so.
Right now I will have a meeting outside the company and will out for the day.
As soon as time permit, I will prepare another repro app including the app.config file and send it to you.
Thanks for your efforts.
Eduardo Quintana
Director of Development
SFTWY CDI Ltda.
5511-5686-6226 / 5511-3578-1689 / 5511-8317-9947
From: [email removed]
Sent: Monday, January 17, 2011 9:16 AM
To: [email removed]
Subject: Re: Unable to cast object of type '...UnityBlockExtension' to type '...UnityContainerExtention' [entlib:241357]

From: AvanadeSupport

No, it should really be in the host executable project. I don't understand why it won't work for you. Could you send me another repro including the app.config file?

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com