dependency injection exception

Posts   
 
    
peerke
User
Posts: 23
Joined: 19-Aug-2008
# Posted on: 19-Aug-2008 10:14:08   

Hi,

I'm currently evaluating LLBLGen Pro v.2.6 and want to understand the DI mechanism. I looked at the validator example application that is available for download (this works fine), but I just can't get it to work in my own application cry

I get this exception: "The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception."

My validation class is located in an assembly separate from the assembly where my business classes are. I use a small console app to test my code. I manually copied the validator assembly to the bin folder of the console application.

This is the line in the console app I get the error on:


CustomerEntity cust = new CustomerEntity();

My app.config:


<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="dependencyInjectionInformation" type="SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler, SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27"/>
    </configSections>

    <dependencyInjectionInformation>
        <additionalAssemblies>
            <assembly fullName="Foo.TestProject.Validators, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </additionalAssemblies>
    </dependencyInjectionInformation>

    <appSettings>
        <add key="Main.ConnectionString" value="data source=***;initial catalog=Northwind;integrated security=SSPI;persist security info=False;packet size=4096"/>
    </appSettings>
</configuration>


My validator class:


using System;
using System.Text;
using Foo.TestProject.EntityClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace Foo.TestProject.Validators
{
    [DependencyInjectionInfo(typeof(CustomerEntity), "ValidatorToUse")]
    [Serializable]
    public class CustomerValidator : ValidatorBase
    {
        public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
        {
            // value to return
            bool fieldIsValid = true;
            if (value != null)
            {
                switch ((CustomerFieldIndex)fieldIndex)
                {
                    case CustomerFieldIndex.CompanyName:

                        // check for length of name
                        if (((string)value).Length > 25)
                        {
                            // set error info, so we could check that outside
                            involvedEntity.SetEntityFieldError(CustomerFieldIndex.CompanyName.ToString(), "The companyname is too long.", false);
                            fieldIsValid = false;
                        }
                        else
                        {
                            // everything seems to be OK with this field so we clean the error info.
                            involvedEntity.SetEntityFieldError(CustomerFieldIndex.CompanyName.ToString(), "", false);
                        }
                        break;
                }

            }
            // return valid field status
            return fieldIsValid;
        }

     }
}


Stacktrace:

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(Object injectionTarget) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.PerformDependencyInjection() at Foo.TestProject.EntityClasses.CustomerEntityBase.InitClassMembers() in C:\Documents and Settings\diepeer\My Documents\LLBLGen Pro Projects\EntityBaseClasses\CustomerEntityBase.cs:line 710 at Foo.TestProject.EntityClasses.CustomerEntityBase.InitClassEmpty(IValidator validatorToUse) in C:\Documents and Settings\diepeer\My Documents\LLBLGen Pro Projects\EntityBaseClasses\CustomerEntityBase.cs:line 625 at Foo.TestProject.EntityClasses.CustomerEntityBase..ctor() in C:\Documents and Settings\diepeer\My Documents\LLBLGen Pro Projects\EntityBaseClasses\CustomerEntityBase.cs:line 85 at Foo.TestProject.EntityClasses.CustomerEntity..ctor() in C:\Documents and Settings\diepeer\My Documents\LLBLGen Pro Projects\EntityClasses\CustomerEntity.cs:line 41 at TestApp.Program.Main(String[] args) in C:\Documents and Settings\diepeer\My Documents\TestApp\Program.cs:line 19

Any help is greatly appreciated!

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Aug-2008 14:17:40   

In Visual Studio, the assembly name can be viewed and changed through the project's property pages dialog box

Having said so, then you should be using the following:

<assembly fullName="myAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 

So make sure "Foo.TestProject.Validators" is the assembly name, otherwise use the correct one instead of "myAssemblyName" mentioned in the above example.

peerke
User
Posts: 23
Joined: 19-Aug-2008
# Posted on: 19-Aug-2008 14:28:19   

Hi Walaa,

Thanks for looking at my issue. I double-checked the name of my Validator-assembly. It really is "Foo.TestProject.Validators", so the dependencyInjectionInformation-entry in my app.config file seems to be ok:

    <dependencyInjectionInformation>
        <additionalAssemblies>
            <assembly fullName="Foo.TestProject.Validators, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </additionalAssemblies>
    </dependencyInjectionInformation>

Do you have any other suggestions what might be wrong here?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Aug-2008 14:40:05   

Would you please try to use the <assembly filename="xxx.dll"/> tag, instead of the <assembly fullname.../> tag?

peerke
User
Posts: 23
Joined: 19-Aug-2008
# Posted on: 19-Aug-2008 14:46:43   

I did, but unfortunately it gives me the same exception:

<assembly filename="C:\Documents and Settings\User123\My Documents\Foo.TestProject.Validators\bin\Debug\Foo.TestProject.Validators.dll" />

I'm completely lost here confused

peerke
User
Posts: 23
Joined: 19-Aug-2008
# Posted on: 19-Aug-2008 14:56:03   

Solved it, the problem was in in the 'propertyName'-argument of the DependencyInjectionInfo-attribute:

I changed this:


    [DependencyInjectionInfo(typeof(CustomerEntity), "ValidatorToUse")]
    [Serializable]
    public class CustomerValidator : ValidatorBase
   {
       ...
   }

into this:


    [DependencyInjectionInfo(typeof(CustomerEntity), "Validator")]
    [Serializable]
    public class CustomerValidator : ValidatorBase
   {
       ...
   }

Thanks for your help!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Aug-2008 15:07:12   

Would you please attach a simple repro solution?

peerke
User
Posts: 23
Joined: 19-Aug-2008
# Posted on: 19-Aug-2008 15:47:49   

Sure!

I attached my VS2005 solution as it worked for me. To reproduce the error, change "Validator" (in de CustomerValidator class) into something else...

Also, don't forget to modify the connection string in the app.config of the console app (it uses Northwind) and to copy the Validator assembly to the bin folder of the console app.

Regards, peerke

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Aug-2008 16:10:52   

I copied the Foo.TestProject.Validators.dll into the test App bin folder and every thing worked just fine.

The validator assembly should be found in the bin folder of the assembly where you have configured DI (same assembly where you used the app.config for DI configuration).