2010-12-10

ViewState problems with Sandbox Web Parts in SharePoint 2010

I have been playing around with developing sandbox web parts for SharePoint 2010 Foundation. With one particular web part, i had a form that was pretty large, over 300 fields. Initially i had no problems with the form loading and submitting. Gradually i started to convert some of the fields to dropdownlists, and databinding not insignificant datasets. At some point the form started to still display, but would not submit. I kept getting the generic error.

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.

My first attempt to solve this, was to locate the error. I try/catched all of the UI events. Strangely the exception was not being caught. Odd. Next i tried disabling sections of logic in web part and found that if i disabled the databind logic, i got no error. I figured it must have been one of the datasets causing an issue (but really that was a wrong assumption now that i know the true cause). So I continued on. I had to spend a while finding which dropdown sets were causing the problem, but i did narrow it down to one dataset, which also happened to be the largest. Hmm the largest, i had a feeling it might have something to do with a httppost max size at this point. So i reduced the dataset to only 50 records. Sure enough the error went away. With a few tests and page view sources, i found that the error would happen when the form size went over 128KB no matter what dataset had the largest amount of records.

I then decided to look at the ULS logs (which i probably should have done first) and had this error trace


SPUCWorkerProcess.exe (0x165C) 0x1744 SharePoint Foundation Sandboxed Code Service fe8s Medium - - Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. - userCodeWrapperType = "Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper", userAssemblyGroupId = "E8C0D7A9294B4BCCB63757BF4AB4BC47-UCftMMyPOXDR6ibqgsTcXIE7gh71nqlnnuite7AdBB8=", siteCollectionId = "c02189c4-1dea-4969-b2b8-8240dfe4ef65" - Inner Exception: Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Value cannot be null. Parameter name: path1 at System.IO.Path.Combine(String path1, String path2) at System.Web.HttpRawUploadedContent.TempFile..ctor() at System.Web.HttpR...
SPUCWorkerProcess.exe (0x165C) 0x1744 SharePoint Foundation Sandboxed Code Service fe8s Medium ...awUploadedContent.AddBytes(Byte[] data, Int32 offset, Int32 length) at System.Web.HttpRequest.GetEntireRawContent() at System.Web.HttpRequest.FillInFormCollection() at System.Web.HttpRequest.get_Form() at System.Web.HttpRequest.get_HasForm() at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) at System.Web.UI.Page.DeterminePostBackMode() at Microsoft.SharePoint.UserCode.SPUserCodePage.DeterminePostBackMode() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- Server stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean inc...
SPUCWorkerProcess.exe (0x165C) 0x1744 SharePoint Foundation Sandboxed Code Service fe8s Medium ...ludeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.ExecuteHttpRequest(SPUserCodeWebPartHttpRequestContext webPartExecutionContext, SPUserCodeWebPartHttpResponse httpRequestResponse) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.Execute(SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.ExecuteWrapper(SPUserCodeWrapper wrapper, SPUserCodeExecutionContext executionContext) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage...
SPUCWorkerProcess.exe (0x165C) 0x1744 SharePoint Foundation Sandboxed Code Service fe8s Medium ...(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.CodeToExecuteWrapper.EndInvoke(IAsyncResult result) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyO...
SPUCWorkerProcess.exe (0x165C) 0x1744 SharePoint Foundation Sandboxed Code Service fe8s Medium ...perationToken, SPUserCodeExecutionContext executionContext)
SPUCHostService.exe (0x12E4) 0x14CC SharePoint Foundation Sandboxed Code Service fe3r Medium - - Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. - Monitored process "ipc://f28fa0e5-d648-4c74-a67f-4ae8dc6f1856:7000" has encountered an unhandled exception while executing user code. - Inner Exception: Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Value cannot be null. Parameter name: path1 at System.IO.Path.Combine(String path1, String path2) at System.Web.HttpRawUploadedContent.TempFile..ctor() at System.Web.HttpRawUploadedContent.AddBytes(Byte[] data, Int32 offset, Int32 length) at System.Web.HttpRequest.GetEntire...
SPUCHostService.exe (0x12E4) 0x14CC SharePoint Foundation Sandboxed Code Service fe3r Medium ...RawContent() at System.Web.HttpRequest.FillInFormCollection() at System.Web.HttpRequest.get_Form() at System.Web.HttpRequest.get_HasForm() at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) at System.Web.UI.Page.DeterminePostBackMode() at Microsoft.SharePoint.UserCode.SPUserCodePage.DeterminePostBackMode() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- Server stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, ...
SPUCHostService.exe (0x12E4) 0x14CC SharePoint Foundation Sandboxed Code Service fe3r Medium ...Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.ExecuteHttpRequest(SPUserCodeWebPartHttpRequestContext webPartExecutionContext, SPUserCodeWebPartHttpResponse httpRequestResponse) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.Execute(SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.ExecuteWrapper(SPUserCodeWrapper wrapper, SPUserCodeExecutionContext executionContext) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) ...
SPUCHostService.exe (0x12E4) 0x14CC SharePoint Foundation Sandboxed Code Service fe3r Medium ... at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.CodeToExecuteWrapper.EndInvoke(IAsyncResult result) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext executionContext)


The key text being

Value cannot be null.
Parameter name: path1
at System.IO.Path.Combine(String path1, String path2)
at System.Web.HttpRawUploadedContent.TempFile..ctor()

I have seen something like this before, when trying to use file uploads in a sandbox web part. Basically the HTTP object in the SPUCWorkerProcess is not fully functional. You can see how the process works from here http://msdn.microsoft.com/en-us/library/ff798382.aspx. So what was this error telling me, and how did it relate to the 128KB limit i was seeing? I had a guess that at this limit, the http object stopped buffering the request in memory and started writing it to a temporary file on disk. Took a few google searchs to find the appropriate key to set to increase this limit http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestlengthdiskthreshold.aspx. I set this on the sharepoint vss web.config. But this didnt fix the problem.

Both of the sandbox processes are well ... processes. SPUCHostService.exe/SPUCHostService.exe. I doubted that they would have httpRuntime settings i could change. But i went to the folder to see. Inside the folder i found an extra web.config (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode\web.config), maybe i could use that. I added and tried again. To my surprise it fixed the problem.

Well it fixed the problem for my local machine, too bad that solution would not work on a hosting provider. There would be little chance they would change their UserCode settings for me. My next question was, why was so much data being sent the to sandbox process in the first place. Remember this only happens when the form is submitted. I took a guess that it was related to the viewstate, so tried disabling that, and bingo the problem went away. It does mean though that i'm going to have to manually deal with the postback binds, but at least the form is not crashing now.

43 comments:

Anonymous said...

This is what I have been searching in quite a few web pages and I ultimately identified it right here. Wonderful post. I am so impressed. Could under no circumstances imagine of these a point is attainable with it…I imagine you have a excellent information in particular while dealings with these kinds of topics.
[url=http://www.bestdigitalcamerasreview.net]Canon Camera Reviews[/url]

tariqueafzal said...

Its a nice article, but please help me regarding ViewState problem in Snadboxed Visual web part solution,

I have a sandoxed visual web part, in this webpart i have radiobuttonlist and submit button, radiobuttonlist bind with the list data, and on submit required the selected option from the radiobuttonlist, but it doesn't happen, on page postback radiobuttonlist collection is empty and its selecctedindex is -1 :(

how can i reload the viewstate from sandboxed visual web part solution so fetches the selected option from the radiobuttonlist?

Anonymous said...

I was curious if you ever thought of changing the page layout of your website?

Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having one or
two images. Maybe you could space it out better?


My site ... jewellery stores in uk

Anonymous said...

Your kindness shall be tremendously appreciated.


Here is my website: statusnet.bastianhofmann.de

Anonymous said...

Kindly send me the comprehensive notes about "Make PCB using a laser printer-Printed Circuit Panels"
our students could know it and take notes.

Visit my page xerox Phaser 8560

Anonymous said...

Thank you a lot! I have actually saved hours of time at the office!



Also visit my blog :: http://people.cccatholic.or.kr/index.php?document_srl=2655

Anonymous said...

Hiya! I know this is kinda off topic but I'd figured I'd ask.
Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa?
My blog goes over a lot of the same subjects as yours and I think we could
greatly benefit from each other. If you are interested
feel free to shoot me an email. I look forward to hearing from you!
Excellent blog by the way!

my web site; xerox 8560 ink sticks

Anonymous said...

Great article, Claire!

Feel free to visit my page - danon jewellery sale

Anonymous said...

It's very simple to find out any matter on net as compared to books, as I found this paragraph at this website.

my web page: xerox 8560 printer

Anonymous said...

Very useful information, I have actually constantly liked laser printers due to the fact that they are much
less costly to make use of, when you make the preliminary financial investment.
Toner cartrages are much more expensive yet outlast several numerous inkjet cartrages
and are less untidy to utilize. You can set your laser printer
to print in grayscale and use much less of the color toner,
I just use shade when publishing images.

my web-site ... http://farizalakbar.wordpress.com/2012/08/22/Inilah-2-game-hd-android-terbaik/

Anonymous said...

Hello just wanted to give you a quick heads up. The text in your
article seem to be running off the screen in Firefox.

I'm not sure if this is a formatting issue or something to do with web browser compatibility but I thought I'd post to let you know.
The layout look great though! Hope you get the issue resolved soon.
Many thanks

My web blog: mknet360.com

Anonymous said...

Beauitful Prize. loving the blog xx

Here is my page :: danon jewellery stockists

Anonymous said...

There is certainly a lot to learn about this issue.
I like all of the points you have made.

Here is my homepage pilgrim jewellery wholesale

Anonymous said...

This idea really is the simplest way to make tags for folks who have a hard time making tags.

If you are having problem with positioning, you can easily adjust margins and tabs to place it better
for yourself.

Also visit my blog post ... xerox phaser 8560 ink

Anonymous said...

Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn't show up. Grrrr... well I'm not writing all that over again.
Regardless, just wanted to say superb blog!

Here is my website; xerox 8560 solid ink

Anonymous said...

This is a good write-up regarding Postscript limitcheck mistakes.
I do have one inquiry, however. You state not
to publish making use of a printer queue. Could you discuss
your explanations?

My blog post :: xerox phaser 8560 ram error

Anonymous said...

hey JOJO kindly deliver me a video clip on the best ways to make pcb making use
of laser printer and ferric chloride.

Also visit my web site: http://fengshui-sg.blogspot.fr/2007/10/what-is-in-store-for-year-2008.html

Anonymous said...

Replaced the cartridge, same concern with grinding. Have no idea what to do since its 6 years
old, and no real repair work places. I could tear it apart and consider
it. Thanks.

Look into my web site ... Xerox Phaser 8560 Ink Sticks

Anonymous said...

the industry very beautiful one :) your swapper will probably
be lucky :)

Also visit my webpage: how to clean silver jewellery

Anonymous said...

Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I
get actually enjoyed account your blog posts. Any way I will be subscribing to your
augment and even I achievement you access consistently fast.


my blog: solid ink 8560

Anonymous said...

After looking into a few of the blog articles on your website, I honestly like your way of
writing a blog. I book marked it to my bookmark website list and will be checking back
in the near future. Please visit my website too and
let me know what you think.

Here is my website xerox 8560 maintenance kit

Anonymous said...

I regard something really special in this website .

Also visit my site: danon jewellery uk

Anonymous said...

I find it too difficult buying diamond engagement rings, but you possibly can the perfect ring, it is very rewarding.


my blog :: silver jewellery

Anonymous said...

We're glad into the future a cross of this site it's realy nicearticle.



my website - silver jewellery UK

Anonymous said...

What's up, its nice piece of writing about media print, we all be aware of media is a wonderful source of data.

my page pilgrim jewellery stockists (http://dar01726mc.wallinside.com)

Anonymous said...

Ah, have no idea exactly how I missed that concerning the variation variety.

The funny point is that the unsigned driver on the ML-1210 page is additionally version 3.
01. Anyhow, I will certainly update the blog post to make this a little more clear.


Feel free to surf to my web page ... xerox phaser 8560 color printer [www.david-laserscanner.jp]

Anonymous said...

Excellent goods from you, man. I have bear in mind your stuff prior to and you are
just too fantastic. I actually like what you've bought right here, really like what you are stating and the best way by which you are saying it. You make it enjoyable and you continue to care for to stay it smart. I can not wait to read far more from you. This is really a wonderful web site.

Also visit my web blog: pilgrim jewellery stockists edinburgh

Anonymous said...

Hey there,
How can I resolve my issue? That I couldn't connect the LaserJet 1018 printer to my PS attempted everything and I then reinstalled the printer motorist and it wont work's.
if they aren't visiting assist a printer, it ought to be on the box.

Look at my blog post - Xerox Phaser 8560Mfp

Anonymous said...

Everyone loves the Pearl White Rose Hair Pin. It's a beautiful classic piece which is timeless. I'm always astounded by the artist
talent everyone has along with the smart ways they will use it.
Stay the best Corinne, you're doing best wishes! And Mara, that's
so types of someone to feature such great develop your site:
)

My webpage :: web site

Anonymous said...

Hi, I think your website might be having browser compatibility problems.
When I look at your website in Safari, it looks fine however when opening
in IE, it's got some overlapping issues. I simply wanted to provide you with a quick heads up! Aside from that, excellent blog!

Look into my web-site; xerox 8560 review

Anonymous said...

The home Theater Along with Ambient Lumination

My blog :: how to convert video to mp3

Anonymous said...

Many thanks great deals. Works a treat.

Review my homepage xerox phaser 8560 color printer ()

Anonymous said...

Good day, Do you think its additionally great to
acquire a used inkjet for home usage? Where can i discover Amazon or Best-Buy?


Here is my webpage - xerox phaser 8560dn :: Www.inbalpazmusic.com :
:

Anonymous said...

Howdy this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors
or if you have to manually code with HTML. I'm starting a blog soon but have no coding experience so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

My web blog - xerox 8560 phaser

Anonymous said...

i really like the ddearings

Have a look at my weblog; designer silver jewellery

Anonymous said...

Great post, you may have talked about some excellent points , I too conceive this s an
extremely excellent website.

Feel free to surf to my site :: silver jewellery (www.article-crash.info)

oakleyses said...

tory burch outlet, polo ralph lauren, ugg boots, chanel handbags, tiffany jewelry, longchamp outlet, longchamp pas cher, gucci handbags, sac longchamp pas cher, uggs on sale, jordan pas cher, michael kors pas cher, ray ban sunglasses, oakley sunglasses, polo outlet, louboutin pas cher, longchamp outlet, burberry pas cher, louis vuitton, cheap oakley sunglasses, replica watches, replica watches, longchamp outlet, christian louboutin outlet, prada handbags, oakley sunglasses wholesale, louis vuitton outlet, oakley sunglasses, ray ban sunglasses, louis vuitton, prada outlet, nike outlet, louis vuitton outlet, christian louboutin, nike free run, nike roshe, ugg boots, nike air max, polo ralph lauren outlet online, kate spade outlet, christian louboutin uk, tiffany and co, nike free, oakley sunglasses, jordan shoes, louis vuitton outlet, nike air max, ray ban sunglasses

oakleyses said...

nike tn, ralph lauren uk, true religion outlet, nike air max uk, burberry handbags, michael kors, abercrombie and fitch uk, nike blazer pas cher, oakley pas cher, timberland pas cher, hogan outlet, uggs outlet, michael kors outlet online, replica handbags, sac vanessa bruno, true religion outlet, converse pas cher, guess pas cher, ray ban pas cher, ray ban uk, true religion outlet, michael kors outlet, mulberry uk, nike roshe run uk, hollister uk, coach outlet, kate spade, nike air max, new balance, true religion jeans, north face, coach outlet store online, uggs outlet, michael kors outlet online, polo lacoste, michael kors outlet, lululemon canada, nike air force, vans pas cher, michael kors outlet, hollister pas cher, michael kors outlet online, sac hermes, michael kors, burberry outlet, michael kors outlet online, north face uk, nike air max uk

oakleyses said...

converse, louboutin, soccer jerseys, ferragamo shoes, hermes belt, longchamp uk, p90x workout, north face outlet, baseball bats, instyler, nike trainers uk, babyliss, mont blanc pens, soccer shoes, nfl jerseys, valentino shoes, oakley, hollister clothing, abercrombie and fitch, chi flat iron, ralph lauren, nike air max, north face outlet, gucci, ray ban, vans, beats by dre, herve leger, jimmy choo outlet, giuseppe zanotti outlet, mac cosmetics, ghd hair, reebok outlet, nike roshe run, hollister, mcm handbags, timberland boots, nike air max, lululemon, bottega veneta, insanity workout, nike huaraches, vans outlet, hollister, iphone cases, wedding dresses, new balance shoes, converse outlet, asics running shoes, celine handbags

oakleyses said...

marc jacobs, ugg,uggs,uggs canada, louis vuitton, swarovski, barbour uk, montre pas cher, moncler outlet, louis vuitton, canada goose outlet, louis vuitton, pandora charms, wedding dresses, juicy couture outlet, moncler, canada goose outlet, louis vuitton, canada goose uk, ugg uk, canada goose, ugg pas cher, coach outlet, hollister, moncler, canada goose outlet, ugg, pandora jewelry, moncler outlet, karen millen uk, pandora jewelry, links of london, louis vuitton, canada goose, canada goose, swarovski crystal, moncler uk, moncler, moncler, doudoune moncler, juicy couture outlet, canada goose jackets, thomas sabo, replica watches, ugg,ugg australia,ugg italia, barbour, pandora uk, supra shoes, lancel, toms shoes

Blogger said...

Are you making money from your exclusive shared links?
Did you know that Mgcash will pay you an average of $500 per 1,000 unlocks?

chenlina said...

chenlina20171116
uggs outlet
ray ban
uggs
canada goose sale
michael kors outlet
nba jerseys
ugg boots cheap
birkenstock sandals
ugg outlet
uggs outlet

ASO Services said...

Thanks a lot for sharing this with all of us, I like it and we can communicate. Do you need buy app ratings and reviews. To boost app ranking and double app downloads now.