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
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.