Archive for October, 2013
The specified cast from a materialized ‘System.Int64’ type to the ‘System.Int32’ type is not valid
Posted by sgtcodeboy in ASP.NET CSharp, Computer Code, Things to Remember on October 30, 2013
I ran into a sql related .net error today. If you read the title of the post you’ve probably guessed what it is. If not here’s the error:
The specified cast from a materialized ‘System.Int64’ type to the ‘System.Int32’ type is not valid.
Google was marginally helpful, but if you’re like me when you google an error you’re hoping for that post that says: If you see ABC, then you have done XYZ, do 123 to fix the error. In this case the error is saying there’s a datatype problem. Something about a Long and an Int. My app only has ints. No longs in the schema at all. This specific error came out of an entity framework method, so I couldn’t easily pinpoint it to a given column. 98% of my app is pure entity framework, mostly code-first (though I do write out transactional schema patches to update the database in a scripted manner.) There is one stored procedure in the app, and this stored proc I had just changed to add some new features specifically paging from the sproc.
In this case, the sproc looked like this:
Reports_MyReport SomeGuidID
it returned data of the report, field1,field2, field3 etc..
My change was to add paging directly to the sproc, reduce the amount of data leaving the box as this report was going to get hit a lot.
Reports_MyReport SomeGuid, PageNumber, PageSize
it returns data like RowNumber, Field1, Field2, Field3, TotalRows
I tested out the changes, they worked great, no nulls where they weren’t expected.
Upon running the new sproc through my app, i got the error listed above. It turned out that my sproc, which had code like this:
select RowNumber, Field1, Field2, Field3, @totalRows as TotalRows ….
was the culprit. @totalRows was being interpeted as a int64, as that was comming from an @@ROWCOUNT function. I know i’ll never have more than int32 rows in that table, so for me switching by casting to Int32 solved the problem:
select RowNumber, Field1, Field2, Field3, cast(@totalRows as int) as TotalRows ….
Problem solved, error gone!
Hopefully by the time I have completely forgotten about this, and make the exact same mistake again – in six months – this post will be living in the googles. Hopefully this helps someone else as well.
Scott
Maximum call stack size exceeded when using Modals and AngularJS
Posted by sgtcodeboy in Uncategorized on October 29, 2013
Saw a really wierd error today, as you can guess from the title of the post it has to do with Maximum Call stack size exceeded, modals and AngularJS. First a bit about the app. I’m currently building a table of data, its basically a status report, so the url might be http://mysite.com/#/report/myreport which would show you the list of data. However I’m also building a detail page that will use a modal popup when you double click on a given row of the report. I wanted this to be addressable so it would have its own url. So basically i’ve got my angularjs route setup with an optional rowid parameter.
Request this: http://mysite.com/#/report/myreport and you see the report show up.
Request this: http://mysite.com/#/report/myreport/32 and you see the report in the background with a modal overlay showing the details of row 32.
You can close the modal, view other records, the url changes as you do so. All in all, its a pretty simple angularjs app. No new concepts for me, I’ve used modal before, controllers etc all of it. However, today when i wired up my code to load the modal when the page first loads, I saw an evil error in chrome:
Uncaught RangeError: Maximum call stack size exceeded. jQuery.event.special.focus.trigger…. tons of jquery calls ….
Only in chrome, FIrefox acted a bit wierd, and IE well IE i’ll save for another day. I tried googling it, all the results pointed to a recursive loop, but i had no recursive code. Google was actually pretty unhelpful for this error. I backed out all my changes for the instant modal popup functionality, and instead just wrote a log entry to the console.
The error didn’t appear, the log entry did appear, twice. Somehow my controller was loading and running twice. Googling that was helpful, I found this: http://stackoverflow.com/questions/15535336/combating-angularjs-executing-controller-twice
It turned out I was doing the exact same thing. I had no idea you were not supposed to register the controller at the top of the page if you were using routing. Removing that single html attribute solved the dual log entry problem. I then re-enabled my instant modal on load code, and that all worked without error as well. Somehow with the controller loading twice and my code running at startup caused some wierd stack overflow.
Once it was loading only once the problem went away. So here’s another post for google, I’m sure I’ll make this mistake again sometime, probably in about three months or so. Hopefully then I’ll google it and find my own blog post.
Bundling AngularJS
Posted by sgtcodeboy in Uncategorized on October 22, 2013
There’s lots of posts out there on how to correctly bundle angularjs with any of the popular bundling tools. I happen to use MVC’s built in bundling. It works for me now, though I am looking at using less and gruntjs for some additional functionality. Here’s a recent problem that I solved.
I would see an error that looked something like this:
Module Error
error in component $injector
Failed to instantiate module myApp due to:
Error: [$injector:unpr] http://errors.angularjs.org/undefined/$injector/unpr?p0=n
at Error ()
at http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:130753
at http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:143147
at i (http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:141792)
at Object.r [as invoke] (http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:141964)
at http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:141398
at Array.forEach (native)
at r (http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:131065)
at p (http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:141201)
at sf (http://myapp.mysite.com/bundles/app?v=xmkhVlgjOx7Eo5ltsK1SZpAavJM1dB6-bg-ujblqCgc1:1:143261
I was pretty confused as to what was going on, I’d properly configured all of my controllers so they used an array like [‘$http’, ‘$q’, …] for injection. What was going on.
It turned it out it was one simple error. In my app.js which handles the routing, I had code looking like this:
myApp .config(function ($routeProvider) {
$routeProvider.
That turned out to be the issue. Once i refactored it to look like this:
myApp.config([“$routeProvider”, function ($routeProvider) {
$routeProvider.
It then bundled nicely and no javascript errors. I should have noticed immediately when it said a module error, but I didn’t. Hopefully this post gets into google and helps someone else.