Error when binding Listview Field using "PopulateThroughEvent"


Author
Message
Ruchika Garg
Ruchika Garg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: StrataFrame Users
Posts: 17, Visits: 70
 I am getting invalid cast expception when i am trying to cast the e.BusinessObject

AccountAddresses accountAddressBO = accountAddressBO = (AccountAddresses)e.BusinessObject;

I have attached few images to show the listview settings and events.

Thank you,

Ruchika.

Attachments
Setting.png (171 views, 23.00 KB)
Code.png (175 views, 47.00 KB)
ExceptionMessage.png (163 views, 50.00 KB)
Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
OK, this one took me a few minutes to figure out. First of all, if you actually deployed the project, it would work. So if you took exactly what you have and ran it through IIS or a test or production server (outside of the ASP.NET Development Server that runs out of VS in your system tray) it would work and will work.



The problem that you are running into is a .NET issue as to how it pre-compiles the application to run in a debug mode (good news is ahead so don't worry Wink ), it dumps all assemblies into the Temporary ASP.NET folder (i.e. C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files) each time the app is run from within the VS environment. So when you create a reference to an assembly in code, it will shift the references and pull from this temporary ASP.NET files location. But StrataFrame (i.e. the ListView) uses a true resolution (ITypeResolver interface implemented in the ApplicationBasePage) to pull the assembly from the deployed Bin folder (or other sub folder within the compiled application).



So here is what happens when running through the designer:



//-- Pulls the assembly from C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

MyBO x = new MyBO();




where as our logic pulls it from the Bin folder (which is far safer in the long run):



//-- What is going on within the instance creation in SF which pulls from the actual deployed Bin folder

BusinessLayerBase x = (BusinessLayerBase)GetTypeFromReferencedAssemblies("BusinessObjectLibrary1.AccountAddresses" ((Tools.ITypeResolver)this.Page).GetCompilationSection(), this.Page);




Now long term we may make a change to determine if we are running through the designer...but there is a really simple workaround. Just sign the business object library and put it in the GAC on your development machine. You will NOT need to do this when you deploy (nor is it recommended), but this will resolve the casting exception that you are getting and always ensure that you are on the same reference.



You will also want to add a PostBuild Event that throws the BO library assembly in your GAC for you automatically so you don't have to worry about it every time you build. Just use the GACUTIL to automatically add (and overwrite) your assembly into the GAC on the post build event and from that point forward you should be good to go.



One final thought is to call the pre-compile tool on a post-build event and force the output to a totally different location, but this approach could be more cumbersome.
Leonard P.
Leonard P.
StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hi Trent, It all makes sense.

Thank for looking into this.
Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No problem...sorry for the delay...it took me a few minutes to see from where the assemblies were being pulled before I realized what was going on.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ruchika Garg - 15 Years Ago
Trent L. Taylor - 15 Years Ago
Ruchika Garg - 15 Years Ago
Trent L. Taylor - 15 Years Ago
                     Hi Trent,

I was able to reproduce this issue on my machine....
Leonard P. - 15 Years Ago
                         Yeah, this sounds similar as to what I was referencing. It is a...
Trent L. Taylor - 15 Years Ago
                             Hi Trent, I have created and attached a sample project to reproduce...
Ruchika Garg - 15 Years Ago
                                 OK, this one took me a few minutes to figure out. First of all, if...
Trent L. Taylor - 15 Years Ago
                                     Hi Trent, It all makes sense.
Thank for looking into this.
Leonard P. - 15 Years Ago
                                         No problem...sorry for the delay...it took me a few minutes to see...
Trent L. Taylor - 15 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search