ExecuteSprocAccessor throws an "Cannot create a mapping for type T" error

Topics: Data Access Application Block
Sep 4, 2012 at 7:27 AM
Edited Sep 4, 2012 at 7:54 AM

Sirs,

I have written a procedure to get a string as an input and return the list of parameters . I have used the ExecuteSprocAccessor to map the result to a modal which has the properties that are returned by the ExecuteSprocAccessor.

Detailed Exception :

 

System.InvalidOperationException was unhandled  Message=Cannot create a mapping for type CampaignModel.  Source=Microsoft.Practices.EnterpriseLibrary.Data  StackTrace:       at Microsoft.Practices.EnterpriseLibrary.Data.ReflectionRowMapper`1..ctor(IDictionary`2 propertyMappings)       at Microsoft.Practices.EnterpriseLibrary.Data.MapBuilder`1.MapBuilderContext.Build()       at Microsoft.Practices.EnterpriseLibrary.Data.MapBuilder`1.BuildAllProperties()       at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseExtensions.CreateSprocAccessor[TResult](Database database, String procedureName, IParameterMapper parameterMapper)       at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseExtensions.ExecuteSprocAccessor[TResult](Database database, String procedureName, IParameterMapper parameterMapper, Object[] parameterValues)       at SolarWinds.Services.BusinessLayer.Repositories.DataWarehouseCampaignRepository.GetCampignData(String campaignId) in C:\P4\Lokesh.Ravichandru\depot\EnterpriseServices\Main\Services\Src\Lib\SolarWinds.Services.BusinessLayer\Repositories\DataWarehouseCampaignRepository.cs:line 28       at Registration.Campaign.Test.Program.Main(String[] args) in C:\P4\Lokesh.Ravichandru\depot\EnterpriseServices\Main\Services\Registration.Campaign.Test\Program.cs:line 16       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()  InnerException: System.TypeInitializationException       Message=The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Data.ReflectionRowMapper`1' threw an exception.       Source=Microsoft.Practices.EnterpriseLibrary.Data       TypeName=Microsoft.Practices.EnterpriseLibrary.Data.ReflectionRowMapper`1       StackTrace:            at Microsoft.Practices.EnterpriseLibrary.Data.ReflectionRowMapper`1..ctor(IDictionary`2 propertyMappings)       InnerException: System.IO.FileNotFoundException            Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.            Source=Microsoft.Practices.EnterpriseLibrary.Data            FileName=Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35            FusionLog==== Pre-bind state information ===LOG: User = SWDEV\Lokesh.RavichandruLOG: DisplayName = Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified)LOG: Appbase = file:///C:/P4/Lokesh.Ravichandru/depot/EnterpriseServices/Main/Services/Registration.Campaign.Test/bin/Debug/LOG: Initial PrivatePath = NULLCalling assembly : Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.===LOG: This bind starts in default load context.LOG: Using application configuration file: C:\P4\Lokesh.Ravichandru\depot\EnterpriseServices\Main\Services\Registration.Campaign.Test\bin\Debug\Registration.Campaign.Test.vshost.exe.ConfigLOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.LOG: Post-policy reference: Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35LOG: Attempting download of new URL file:///C:/P4/Lokesh.Ravichandru/depot/EnterpriseServices/Main/Services/Registration.Campaign.Test/bin/Debug/Microsoft.Practices.Unity.DLL.LOG: Attempting download of new URL file:///C:/P4/Lokesh.Ravichandru/depot/EnterpriseServices/Main/Services/Registration.Campaign.Test/bin/Debug/Microsoft.Practices.Unity/Microsoft.Practices.Unity.DLL.LOG: Attempting download of new URL file:///C:/P4/Lokesh.Ravichandru/depot/EnterpriseServices/Main/Services/Registration.Campaign.Test/bin/Debug/Microsoft.Practices.Unity.EXE.LOG: Attempting download of new URL file:///C:/P4/Lokesh.Ravichandru/depot/EnterpriseServices/Main/Services/Registration.Campaign.Test/bin/Debug/Microsoft.Practices.Unity/Microsoft.Practices.Unity.EXE.
            StackTrace:                 at Microsoft.Practices.EnterpriseLibrary.Data.ReflectionRowMapper`1..cctor()            InnerException: 

 

Adding more details.

I tried by setting the var resultMapper = MapBuilder<CampaignModel>.MapAllProperties().Build();

I am getting the exception in the above line.

please can anyone say what is the mistake behind this.

Sep 5, 2012 at 1:45 AM

The  inner exception of the StackTrace is:

System.IO.FileNotFoundException Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

Have you deployed the Unity assemblies along with the application?  i.e. Microsoft.Practices.Unity.dll, Microsoft.Practices.Unity.Configuration.dll, Microsoft.Practices.Unity.Interception.dll, Microsoft.Practices.Unity.Interception.Configuration.dll.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 5, 2012 at 7:31 AM

Hi ,

Thanks a lot , that really helps me to solve the issue.

-Lokesh