Microsoft distributes Microsoft SQL Server 2008 R2 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release.
Symptoms
Consider the following scenario:
-
You have a Report Definition Language (RDL) file that contains a Tablix control in Microsoft SQL Server 2008 R2 Reporting Services.
-
You add a row group or a column group to the Tablix control, and then set a group expression to the group data by using a column that has a numeric data type.
-
This column contains a value that is not in the range of the Int32 data type. For example, a value of the column is 9000001777400270.
In this scenario, you receive the following error message when you try to generate the report:
An error occurred during local report processing.
An error has occurred during report processing.
Value was either too large or too small for an Int32.
Resolution
Cumulative update information
SQL Server 2008 R2
The fix for this issue was first released in Cumulative Update 4. For more information about how to obtain this cumulative update package for SQL Server 2008 R2, click the following article number to view the article in the Microsoft Knowledge Base:
2345451 Cumulative Update package 4 for SQL Server 2008 R2 Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
981356 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 was released
Workaround
To work around this issue, convert the numeric data type to the Double data type or to the Int64 data type. To do this, follow these steps:
-
Double-click the group in the Row Groups or Column Groups pane to open the Group properties.
-
On the General tab, change the group expression to the following System.Double data type expression:
CDbl(Fields!<Field Name>.Value)Or, change the group expression to the following System.Int64 data type:
CLng(Fields!<Field Name>.Value)
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.
References
For more information about data types, visit the following websites:
General information about the «Decimal» structure
General information about the «Int32» structure
General information about the «Int64» structure
General information about the «Double» structure
Need more help?
This article is about errors in the Microsoft Small Basic program language. If you know other errors, please add them to this article.
Table of Contents
- Syntax Errors
- The variable ‘xxx’ is used, but its value is not assigned.
- Access is denied.
- The file cannot be accessed by the system.
- N unexpected at this location.
- Operation ‘Xxx.Xxx’ is supplied N arguments, but takes M arguments.
- Cannot find operation ‘Opxxx’ in ‘Objxxx’.
- Cannot find property ‘Prxxx’ in ‘Objxxx’.
- Subroutine ‘Xxx’ is not defined.
- The operation ‘Objxxx.Opxxx’ is expected a return value.
- Expected EndXxx but could not find one in the right place.
- Unexpected token Xxx found.
- Unrecognized statement encountered.
- Cannot find property ‘Prxxx’ in ‘Objxxx’.
- Run Time Errors
- Attempted to divide by zero.
- Exception has been thrown by the target of an invocation.
- Length cannot be less than zero.
- ‘maxValue’ must be greater than zero.
- Object reference not set to an instance of an object.
- Specified cast is not valid.
- The request is not supported.
- Value was either too large or too small for a Decimal.
- Value was either too large or too small for an Int32.
- File Errors
- Access to the path ‘X:Xxx…Xxx.Xxx’ is denined.
- Other Errors
- Microsoft Visual Basic was not found on your machine.
- See Also
- Other Languages
Syntax Errors
When you push [Run] button, two processes are started. The first is compilation. The Small Basic Environment (SB.exe) calls compiler (SmallBasicCompiler.exe) to compile Small Basic source code to msil for the .NET Framework. The second process is to run
that compiled code. The Small Basic Environment calls the generated binary.
At compilation time, the compiler checks the syntax of the source code. If there are any errors in it, the Small Basic Environment shows syntax errors. Following message is a sample of a syntax error. «1, 1:» means the number of line (row) and column
of the error in the source code.
Sorry, we found some errors…
1,1: Subroutine ‘Foo’ is not defined.
These kind of syntax errors are listed on bottom in the active editor. If you click a line of error messages, the cursor will be moved to the line of the source code.
The variable ‘xxx’ is used, but its value is not assigned.
This error occurs if some variable is not initialized in the code at all. Following articles describes about one of a case of this errors.
Small Basic Known Issue: 26720 — Event Subroutines Should Be After They Are Registered
Syntax Error Message
The variable ‘xxx’ is used, but its value is not assigned. Are you sure you have spelled it correctly?
Syntax Error Message (v1.3~)
I need to use the variable ‘xxx’ but it has never been given a value. Is this the right name?
Sample Code
Following code occurs this error.
a
=
b
TextWindow
.
WriteLine
(
"a="
+
a
)
But following code doesn’t occur this error.
a
=
b
TextWindow
.
WriteLine
(
"a="
+
a
)
b
=
a
TextWindow
.
WriteLine
(
"b="
+
b
)
Access is denied.
This error occurs when one of the programs in Small BasicSamples folder is attempt to be run.
Syntax Error Message
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
The file cannot be accessed by the system.
This error occurs when the exe or SmallBasicLibrary.dll in current folder are available only online of your OneDrive. (This error was happened with old OneDrive.)
Syntax Error Message
The file cannot be accessed by the system. (Exception from HRESULT: 0x80070780)
N unexpected at this location.
This error occurs if a number is located the top of a line.
Syntax Error Message
N unexpected at this location.
Syntax Error Message (v1.3~)
I found ‘N’ here when I was not expecting it.
Sample Code
Operation ‘Xxx.Xxx’ is supplied N arguments, but takes M arguments.
If a number of arguments (parameters) of an operation is different, following error will occur.
Syntax Error Message
Operation ‘Xxx.Xxx’ is supplied N arguments, but takes M arguments.
Syntax Error Message (v1.3~)
I was not able to run ‘Xxx.Xxx’ because it needs N arguments, but here it got M arguments instead.
Sample Code
TextWindow
.
Write
(
"Number (0-15)? "
)
decimal
=
TextWindow
.
ReadNumber
(
)
txt
=
"0123456789ABCDEF"
subtxt
=
Text
.
GetSubText
(
txt
,
number
+
1
)
TextWindow
.
WriteLine
(
subtxt
)
TextWindow
.
WriteLine
(
"Hello, "
name)
Cannot find operation ‘Opxxx’ in ‘Objxxx’.
This error occurs when the operation Opxxx is not included in an object Objxxx.
Syntax Error Message
Cannot find operation ‘Opxxx’ in ‘Objxxx’.
Syntax Error Message (v1.3~)
I was unable to find ‘Opxxx’ in ‘Objxxx’.
Sample Code
Text
.
WriteLine
(
"Hello World!"
)
Cannot find property ‘Prxxx’ in ‘Objxxx’.
This error occurs when the property Prxxx is not included in an object Objxxx.
Syntax Error Message
Cannot find property ‘Prxxx’ in ‘Objxxx’.
Syntax Error Message (v1.3~)
I was unable to find a property named ‘Prxxx’ in ‘Objxxx’.
Sample Code
Timer
.
Tick
=
Shapes
.
Move
(
invador
[
1
]
,
inx
[
1
]
,
iny
[
1
]
)
Subroutine ‘Xxx’ is not defined.
If called subroutine is not defined, this error will occur.
Syntax Error Message
Subroutine ‘Xxx’ is not defined.
Syntax Error Message (v1.3~)
I was unable to find a find a Sub named ‘Xxx’.
Sample Code
Foo
(
)
Sub
Bar
TextWindow
.
WriteLine
(
"Bar"
)
EndSub
The operation ‘Objxxx.Opxxx’ is expected a return value.
This error occurs when the operation written in right-hand side of assignment statement doesn’t have return value.
Syntax Error Message
The operation ‘Objxxx.Opxxx’ is expected a return value, but it doesn’t return anything.
Syntax Error Message (v1.3~)
I expected to get a value from ‘Objxxx.Opxxx’ but it doesn’t return anything.
Sample Code
Timer
.
Tick
=
Shapes
.
Move
(
invador
[
1
]
,
inx
[
1
]
,
iny
[
1
]
)
Expected EndXxx but could not find one in the right place.
This error occurs if there is a keyword in an illegal place.
Syntax Error Message
Expected EndXxx but could not find one in the right place.
Syntax Error Message (v1.3~)
A Xxx statement must end with EndXxx. I could not find EndXxx in the right place.
Sample Code
Unexpected token Xxx found.
This error occurs if there is a keyword in an illegal place.
Syntax Error Message
Unexpected token Xxx found.
Syntax Error Message (v1.3~)
I found ‘Xxx’ when I was not expecting it.
Sample Code
Unrecognized statement encountered.
This error occurs if a line has wrong syntax.
Syntax Error Message
Unrecognized statement encountered.
Syntax Error Message (v1.3~)
I was unable to understand this statement.
Sample Code
Cannot find property ‘Prxxx’ in ‘Objxxx’.
This error occurs when the program runs in browser with Silverlight.
Run Time Errors
At running time, if there happens a trouble in Small Basic library, .NET Framework or Windows system, error popup will be displayed like below. In the text box, there is a
stack trace. This includes names of subroutines which are called.
After an error popup, you may see following popup which shows the program has stopped working.
If you have installed Visual Studio, you will see «Debug the program» as follows.
You can see the problem details by pushing [v] button beside «View problem details».
Attempted to divide by zero.
Divided by zero causes this error from Small Basic 1.2.
Exception has been thrown by the target of an invocation.
Following actions cause this error.
- GraphicsWindow.FillRectangle(0, 0, -1, -1)
- Shapes.AddText() at the program top (Fixed for Small Basic v1.2)
- GraphicsWindow.GetPixel(x, y) while x < 0 (Fixed for Small Basic v1.2)
Length cannot be less than zero.
If the length in Text.GetSubText(text, start, length) is less than zero, following error will occurs.
Sample Code
txt
=
"abcdefghijklmnopqrstuvwxyz"
start
=
1
length
=
-
1
subtxt
=
Text
.
GetSubText
(
txt
,
start
,
length
)
TextWindow
.
WriteLine
(
subtxt
)
‘maxValue’ must be greater than zero.
If the maxValue in Math.GetRandomNumber(maxValue) is less than zero, following error will occurs.
Object reference not set to an instance of an object.
Referencing GraphicsWindow.LastText before any text input causes this error.
Specified cast is not valid.
Shapes.GetOpacity() causes following error. Detail of this error is described in a TechNet article
Small Basic Known Issue: 24406 — Shapes.GetOpacity() Causes Cast Error.
The request is not supported.
Following code causes this error in Windows 8.1. (Fixed for Small Basic v1.2)
TextWindow
.
WriteLine
(
"Here"
)
TextWindow
.
Hide
(
)
TextWindow
.
Show
(
)
Value was either too large or too small for a Decimal.
If a value of a variable is larger than
79228162514264337593543950335 (2^96-1) or smaller than —79228162514264337593543950335 (-2^96+1)
then following error occurs. Also Math.Remainder(x, 0) causes this error.
Sample Code
num
=
1
While
"True"
GraphicsWindow
.
Title
=
num
num
=
num
*
10
EndWhile
Value was either too large or too small for an Int32.
An internal type Int32 allows from -2147483648 (-2^31) to 2147483647 (2^31-1) . If the parameter of Math.GetRandomNumber() operation is out of the latter range, following error occurs.
File Errors
Most of File operations return «FAILED» if an error occurs. At that time, File.LastError property contains the error details. See more details
here for file errors.
Access to the path ‘X:Xxx…Xxx.Xxx’ is denined.
If the output file is read-only, this error is set in File.LastError property.
Other Errors
Microsoft Visual Basic was not found on your machine.
If Visual Basic is not installed this error occurs at graduate. Visual Basic is included in Visual Studio 2013. If only Visual Studio 2015 is installed, the same error occurs. The link in this message is old. See
here for the new URL.
See Also
- The Small Basic Environment (IDE)
- Small Basic: Parameter or Return Value Range for Math Function
- Small Basic: How to Debug > Meaning of Error Messages
- Small Basic: Revision Control > Publish Error
- Microsoft Small Basic v1.0: Known Issues
- Small Basic: Error Handling
- Small Basic Online: Errors
- Wiki: Small Basic Portal
Other Languages
- Small Basic: Les Erreurs (fr-FR)
- Remove From My Forums
-
Question
-
User939516264 posted
System.OverflowException: Value was either too large or too small for an Int32.
Why does this error originate in the following line?
«SqlCommand cmd = new SqlCommand(«SELECT Count(*) FROM Contacts», conn)
…….. ……….
DataSetContacts.ContactsRow row = ds.Contacts.NewContactsRow();
………………
row[«ContactNumber»] = Convert.ToInt32(txtContactNo.Text);»ContactNumber field is SqlDbType.Int.
Answers
-
User-158764254 posted
This is because an Int has a maximum value of 2,147,483,647, or, as a phone number… (214) 748-3647. Which means that any phone number higher than that will result in this error. I would recommend storing your phone numbers as a string or as a Int64 / BigInt
/ long.-
Marked as answer by
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
-
User-1581724896 posted
Int64 and BigInt still did not work, but string worked. Thanx
Int64, bigint or long would have worked but as you are storing the phone number in an international format (with paranthesis and hypen), you have to rely on the String datatype.
—————————————————————————————————
Please click Mark as Answer if this helped in solving your problem.-
Marked as answer by
Anonymous
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
- home
- articles
-
quick answersQ&A
Ask a Question
- View Unanswered Questions
- View All Questions
- View C# questions
- View Python questions
- View Javascript questions
- View C++ questions
- View Java questions
-
discussionsforums
- CodeProject.AI Server
- All Message Boards…
- Application Lifecycle>
- Running a Business
- Sales / Marketing
- Collaboration / Beta Testing
- Work Issues
- Design and Architecture
- Artificial Intelligence
- ASP.NET
- JavaScript
- Internet of Things
- C / C++ / MFC>
- ATL / WTL / STL
- Managed C++/CLI
- C#
- Free Tools
- Objective-C and Swift
- Database
- Hardware & Devices>
- System Admin
- Hosting and Servers
- Java
- Linux Programming
- Python
- .NET (Core and Framework)
- Android
- iOS
- Mobile
- WPF
- Visual Basic
- Web Development
- Site Bugs / Suggestions
- Spam and Abuse Watch
-
featuresfeatures
- Competitions
- News
- The Insider Newsletter
- The Daily Build Newsletter
- Newsletter archive
- Surveys
- CodeProject Stuff
-
communitylounge
- Who’s Who
- Most Valuable Professionals
- The Lounge
- The CodeProject Blog
- Where I Am: Member Photos
- The Insider News
- The Weird & The Wonderful
-
help?
- What is ‘CodeProject’?
- General FAQ
- Ask a Question
- Bugs and Suggestions
- Article Help Forum
- About Us
I have a form that adds and subtracts numbers on textbox text change. If I put in a number like 2181003000 — 899763000 I get this error, «Value was either too large or too small for an Int32.». How can I fix this?
protected void TextBoxNPRNA_TextChanged(object sender, EventArgs e) { int a = Convert.ToInt32(TextBoxTUNA.Text); int b = Convert.ToInt32(TextBoxETRNA.Text); int c = Convert.ToInt32(TextBoxNPRNA.Text); TextBoxTNA2.Text = Convert.ToString(a + b + c); TextBoxTR.Focus(); }
Comments
Solution 1
Why do people insist on doing this?
Never use Convert to change the type of user input: use TryParse instead. That way when the user makes a mistake — as they do all the time — you can detect it before it becomes a problem, and tell them exactly what they have to do to fix it:
int a; if (!int.TryParse(TextBoxTUNA.Text, out a)) { // Report problem to user return; }
Comments
Solution 2
An int
can store values between -2^32-1 to 2^32. To store anything larger, use long
data type which can store between -2^64-1 to 2^64.
Comments
Solution 3
int a = Convert.ToInt32(TextBoxTUNA.Text);
Problem in above code with TextBoxTUNA.Text value 2181003000 is
You can not store big no in small.
-2,147,483,648 .. 2,147,483,647 is the range of int datatype; so how can you store 2181003000 in int!!
Its like try to put 1.5 liter into 1 liter can.
You can do something like
Int32 a = Convert.ToInt32(TextBoxTUNA.Text);
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Top Experts | |
Last 24hrs | This month |
CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900
0 / 0 / 0
Регистрация: 20.04.2010
Сообщений: 8
1
20.04.2010, 22:40. Показов 7677. Ответов 1
Здравствуйте подскажите пожалуйста почему в приложении при нажатии на конпку button 1 при добавлении записи возникает исключение
System.OverflowException: Value was either too large or too small for an Int32.
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at Turfirma.Form26.button1_Click(Object sender, EventArgs e) in K:…Form26.cs:line 38
Помогите пожалуйста разобраться. Спасибо.
C# | ||
|
__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь
0
BTW: I was running renode on 64bit ubuntu 16.04
I got it, it’s because I lock it as a button at side bar, if I start it from the button, it would complain: «Value was either too large or too small for an Int32»
it’s ok if I run it from terminal.
I will reopen this, as it sounds to be something we need to fix.
Do I get it right, that you did the following actions?
- Run Renode from the console
- pin it the the side bar
- start Renode from the sidebad
include @scritps/...
- Crash.
Is that correct? Can you please paste the full stack trace of the error that pops up?
Did you mean «include @scripts/single-node/miv.repl» or «include @scripts/single-node/miv.resc». I tried to install Renode from deb package just right now on 64bit Ubuntu 16.04 and can’t replicate the issue as I don’t even know what steps I should do exactly.
One thing which crosses my mind is that you could have multiple mono installed and when you run from the sidebar it has different environment variables than from command line/bash/shell.
The /usr/bin/renode invokes mono wherever it will be found this might be different places depending between running shortcut and using it from the console. From the console probably the bashrc is run as first which will setup custom paths and then mono executed from there will be different.
If you make script like this:
mono --version && read
And then you make a shortcut for it, will display different mono version than when you are running the script from command line?
Hi, PiotrZierhoffer,
Yeah, it’s happened exactly like what you described.
Here’s the detail:
Value was either too large or too small for an Int32.
at System.Convert.ToInt32 (System.Double value) [0x00084] in <71d8ad678db34313b7f718a414dfcb25>:0
at Antmicro.Renode.Logging.ConsoleBackend.GetMessageLinesCountForRow (System.String row) [0x0001d] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at Antmicro.Renode.Logging.ConsoleBackend+<>c.b__25_0 (System.String x) [0x00000] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at System.Linq.Enumerable.Sum[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func
2[T,TResult] selector) [0x0002e] in :0
at Antmicro.Renode.Logging.ConsoleBackend.GetMessageLinesCount (System.String message) [0x00015] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at Antmicro.Renode.Logging.ConsoleBackend.WriteNewLine (System.String line) [0x00028] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at Antmicro.Renode.Logging.ConsoleBackend.Log (Antmicro.Renode.Logging.LogEntry entry) [0x001f5] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at Antmicro.Renode.Logging.Logger+ActualLogger.WriteLogEntryToBackends (Antmicro.Renode.Logging.LogEntry entry) [0x0000f] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at Antmicro.Renode.Logging.Logger+ActualLogger.LoggingThreadBody () [0x00033] in <73acd1120ee04249a578de8dc4a3fbc4>:0
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <71d8ad678db34313b7f718a414dfcb25>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <71d8ad678db34313b7f718a414dfcb25>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <71d8ad678db34313b7f718a414dfcb25>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <71d8ad678db34313b7f718a414dfcb25>:0
at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <71d8ad678db34313b7f718a414dfcb25>:0
Here’s a picture:
Hi, AntonKrug,
I mean «include @scripts/single-node/miv.resc» because repl would not work.
I think there’s only 1 mono installed, below is what I got for «whereis mono»:
mono: /usr/bin/mono /usr/lib/mono /etc/mono /usr/share/mono /usr/share/man/man1/mono.1.gz
BTW: I did make a script as you said, but I don’t know how to run it’s shortcut by a click, I can’t put it in sidebar and there’s no terminal or bash option in «open with» list.
Oh I see, just noticed Ubuntu UI tries to make unpleasant and doesn’t recognize sh script as executable. Let’s just check if what version it is, run the mono --version
from a terminal.
Started clean VM, went to mono-project to add the mono repository, installed mono-complete instead of recommended mono-develop. Then I installed by hand screen,gksu, gtksharp2 with apt-get. Then downloaded DEB file of Renode 1.4.1 from the github and installed it with dpkg -i …
Just wild guess, could it this issues linked with the file-failing-to-download issue? I attached you the elf file in the previous thread to see if that will have an effect. I cleared my renode cache/index and disabled my networking but can’t trigger the issue from sidebar nor from the terminal.
Once I encountered an issue when I installed the packages in slightly odd order. So I’m still curious about your installed packages, not sure, but maybe the cat /var/log/apt/history.log
could tell something?
Sorry for not being very helpful
Hi, AntonKrug,
you are very helpful :), thank you.
here’s what you want:
mono —version
Mono JIT compiler version 5.12.0.226 (tarball Thu May 3 09:48:32 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: supported, not enabled.
apt_install.log
@zzzh is this error repeatable for you? Or was it a one time event?
The error was most likely caused by Console.WindowWitdh
reported as 0. Why did that happen? I don’t really know, as it is a standard .NET thing. But if you can repeat it a deterministic way, then maybe we’d be able to debug it.
I would understand if it happened during termination of Renode (e.g. after entering q
command), but your screenshot shows it’s not the case.
Ok, we are able to repeat this error.
We add a Renode.desktop entry to /usr/share/applications
, which gives you a Renode shortcut in the Unity Dash. When you start it, everything works fine.
But when you create the shortcut manually, it does not open the terminal window at all — that’s why we crash.
We will try to prevent the crash, one of the ways to do that is to prevent Renode from starting without the terminal — we will think about the correct approach internally.
What you can do to alleviate your problem is to run grep -ri renode ~/.local/
, open the *.desktop
file it finds and add Terminal=true
to the file. It will cause the shortcut to open the window required for our logger.
You can also find the Renode icon in the Dash and pin it to the Launcher — I think it should help as well.
I always used the supplied shortcut and just dragged and dropped it into the side bar.
I installed the gnome-panel
then generated launcher with it and that worked for me when used from desktop, then moved it to side panel and then it started crashing, even using tab while typing caused the message.
Check for existing terminal sounds good.
@PiotrZierhoffer , Great, good to know you had found the cause of this issue.
I’ll try your way to alleviate it later, since it’s running in vmware, because of a samba issue, I’d return it to a snapshot before install renode.
We actually had a hard time getting a reproducible situation where this happened, but we stumbled upon a similar issue in a different situation. This is now resolved on master
In one of my previous post I had demonstrated how to, Download Large Files from SharePoint Online. While the file download is working perfectly fine, but, I was constantly getting the following error while trying to load/access it’s properties,
Value was either too large or too small for an Int32
Issue
Unable to access the properties of large files in SharePoint Online using CSOM.
Solution
Following is the code snippet I was using to access the properties of any SharePoint file using CSOM,
ListItemCollection listItemsBatch = list.GetItems(camlQuery); clientContext.Load(listItemsBatch, p => p.Include( l => l.FieldValuesAsText, l => l.FieldValuesAsHtml, l => l.DisplayName, l => l.HasUniqueRoleAssignments, l => l.FileSystemObjectType, l => l.Id, l => l.RoleAssignments.Include( r => r.Member, r => r.RoleDefinitionBindings.Include( rd => rd.Name)))); clientContext.ExecuteQuery();
Now, the above piece of code is still working with smaller documents. It’s only with large files, that I was facing this issue.
To solve this, I started commenting out the given properties one by one, to check if one of them is causing the issue with large files. And, as it turned out, I finally got the culprit, FieldValuesAsHtml. When I omitted the loading of FieldValuesAsHtml, the code ran just fine . Here’s the working sample,
ListItemCollection listItemsBatch = list.GetItems(camlQuery); clientContext.Load(listItemsBatch, p => p.Include( l => l.FieldValuesAsText, //l => l.FieldValuesAsHtml, l => l.DisplayName, l => l.HasUniqueRoleAssignments, l => l.FileSystemObjectType, l => l.Id, l => l.RoleAssignments.Include( r => r.Member, r => r.RoleDefinitionBindings.Include( rd => rd.Name)))); clientContext.ExecuteQuery();
Key Takeaways
- In my test cases, smaller files mean, file size between, 1KB-10MB and large files mean, file size between 1.5GB-9GB.
- I omitted all the other properties and loaded only, FieldValuesAsHtml, still the issue remained! So the problem lies with this property only.
- Previously, due to the 2GB limitation on the file size by SharePoint, I had only tested the above code with files of sizes less than 1GB. So this could be an old, untested issue.
- Finally, though I got the code working for me, I still don’t have a proper explanation for it. If anybody has any idea as to why we cannot request this property for large files, then, please share. Would love to know the exact reason. 🙂