Lỗi system.argumentnullexception value cannot be null parameter name stream năm 2024

This "How-to" question is in continuation of the post I posted earlier: Web API transaction management and multiple DWs update/save changes in single transaction. [appeon.com] and got response as well.

Logan,

Thanks very much for the example of controller code. it is working well.

I have a question I am getting this error "System.ArgumentNullException: Value cannot be null. [Parameter 'name']" and I am thinking it is because "datacontext" is missing in below code snippet:

IDataStore ds1= dataUnpacker.GetDataStore["dw_1"]; IDataStore ds2= dataUnpacker.GetDataStore["dw_2"];

I am not able to define datacontext in controller & call it in above code snippet.

any documentation/ "how-to" define and use Data Context in Controller? in my Service Implementation [Service Class] I already have data context defined.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

yafeiguo888 opened this issue

Dec 7, 2020

· 24 comments

Comments

I tested the new version 2.5.2 in my Windows 10, .NET core3.1 Visual Studio 2019 and unfortunately, I got errors in running the following command in C#

Cell.SetCellFormula[string.Format["SUM[C{0}:C{1}]", HeaderRowOffset + 1, totalRow.RowNum - 2 + 1]]; Cell.SetCellFormula["NOW[]"];

The following is the stack trace:

System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. [Parameter 'stream'] Source=System.Private.CoreLib StackTrace: at System.IO.StreamReader..ctor[Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen] at System.IO.StreamReader..ctor[Stream stream] at NPOI.SS.Formula.Function.FunctionMetadataReader.CreateRegistry[] at NPOI.SS.Formula.Function.FunctionMetadataRegistry.GetInstance[] at NPOI.SS.Formula.Function.FunctionMetadataRegistry.LookupIndexByName[String name] at NPOI.SS.Formula.PTG.AbstractFunctionPtg.IsBuiltInFunctionName[String name] at NPOI.SS.Formula.FormulaParser.Function[String name] at NPOI.SS.Formula.FormulaParser.ParseNonRange[Int32 savePointer] at NPOI.SS.Formula.FormulaParser.ParseRangeable[] at NPOI.SS.Formula.FormulaParser.ParseRangeExpression[] at NPOI.SS.Formula.FormulaParser.ParseSimpleFactor[] at NPOI.SS.Formula.FormulaParser.PercentFactor[] at NPOI.SS.Formula.FormulaParser.PowerFactor[] at NPOI.SS.Formula.FormulaParser.Term[] at NPOI.SS.Formula.FormulaParser.AdditiveExpression[] at NPOI.SS.Formula.FormulaParser.ConcatExpression[] at NPOI.SS.Formula.FormulaParser.ComparisonExpression[] at NPOI.SS.Formula.FormulaParser.IntersectionExpression[] at NPOI.SS.Formula.FormulaParser.UnionExpression[] at NPOI.SS.Formula.FormulaParser.Parse[] at NPOI.SS.Formula.FormulaParser.Parse[String formula, IFormulaParsingWorkbook workbook, FormulaType formulaType, Int32 sheetIndex, Int32 rowIndex] at NPOI.XSSF.UserModel.XSSFCell.SetFormula[String formula, FormulaType formulaType] at NPOI.XSSF.UserModel.XSSFCell.SetCellFormula[String formula]

The issue wasn't in prevoius version 2.5.1 and 2.4.1.

Thanks, Daniel Guo

The text was updated successfully, but these errors were encountered:

I'm seeing this when calling the getter for CellFormula, too. Can't repro when testing with locally compiled NPOI, though. Also, I can get the stream for the embedded resource "NPOI.Resources.functionMetadata.txt" from user code without a problem. Somehow this line seems to be failing:

using [StreamReader br \= new StreamReader [typeof [FunctionMetadataReader].Assembly.GetManifestResourceStream [METADATA_FILE_NAME]]]

I'll check the issue soon.

More findings about this issue:

This issue is only appearing in Windows 10 Visual Studio 2019 .NET 5.0/Core 3.1

It disappears when in Windows 10 Visual Studio 2019 .NET Framework 4.5.1

It seems compiling error disappears, but the Formula doesn't fully work and the value is not showing up.

    class FunctionMetadataReader
    {

# if NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

Changes to

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

What's the reasoning behind targeting both netstandard2.0 and netstandard2.1? AFAICT there is no code that uses a netstandard2.1 API that is not in netstandard2.0. Same goes for multi-targeting both net461 and net472.

.NET open source library guidance says:

❌ AVOID multi-targeting as well as targeting .NET Standard, if your source code is the same for all targets.
The .NET Standard assembly will automatically be used by NuGet. Targeting individual .NET implementations increases the *.nupkg size for no benefit.

@mganss your concern makes sense. I'll change the release strategy

cell.SetCellFormula[formula]; doesn't work for me too. And stackTrace: at System.IO.StreamReader..ctor[Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen] at System.IO.StreamReader..ctor[Stream stream] at NPOI.SS.Formula.Function.FunctionMetadataReader.CreateRegistry[] at NPOI.SS.Formula.Function.FunctionMetadataRegistry.GetInstance[] at NPOI.SS.Formula.Function.FunctionMetadataRegistry.LookupIndexByName[String name] at NPOI.SS.Formula.PTG.AbstractFunctionPtg.IsBuiltInFunctionName[String name] at NPOI.SS.Formula.FormulaParser.Function[String name] at NPOI.SS.Formula.FormulaParser.ParseNonRange[Int32 savePointer] at NPOI.SS.Formula.FormulaParser.ParseRangeable[] at NPOI.SS.Formula.FormulaParser.ParseRangeExpression[] at NPOI.SS.Formula.FormulaParser.ParseSimpleFactor[] at NPOI.SS.Formula.FormulaParser.PercentFactor[] at NPOI.SS.Formula.FormulaParser.PowerFactor[] at NPOI.SS.Formula.FormulaParser.Term[] at NPOI.SS.Formula.FormulaParser.AdditiveExpression[] at NPOI.SS.Formula.FormulaParser.ConcatExpression[] at NPOI.SS.Formula.FormulaParser.ComparisonExpression[] at NPOI.SS.Formula.FormulaParser.IntersectionExpression[] at NPOI.SS.Formula.FormulaParser.UnionExpression[] at NPOI.SS.Formula.FormulaParser.Parse[] at NPOI.SS.Formula.FormulaParser.Parse[String formula, IFormulaParsingWorkbook workbook, FormulaType formulaType, Int32 sheetIndex, Int32 rowIndex] at NPOI.XSSF.UserModel.XSSFCell.SetFormula[String formula, FormulaType formulaType] at NPOI.XSSF.UserModel.XSSFCell.SetCellFormula[String formula]

Hi guys! Any news about this error?

We are getting the same error in .Net 5 using NPOI 2.5.2 when use SetAutoFilter

ArgumentNullException: Value cannot be null. [Parameter 'stream']
System.IO.StreamReader..ctor[Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen]
System.IO.StreamReader..ctor[Stream stream]
NPOI.SS.Formula.Function.FunctionMetadataReader.CreateRegistry[]
NPOI.SS.Formula.Function.FunctionMetadataRegistry.GetInstance[]
NPOI.SS.Formula.Function.FunctionMetadataRegistry.GetFunctionByName[string name]
NPOI.SS.Formula.FormulaParser.IsValidCellReference[string str]
NPOI.SS.Formula.FormulaParser.ParseSimpleRangePart[]
NPOI.SS.Formula.FormulaParser.ParseRangeable[]
NPOI.SS.Formula.FormulaParser.ParseRangeExpression[]
NPOI.SS.Formula.FormulaParser.ParseSimpleFactor[]
NPOI.SS.Formula.FormulaParser.PercentFactor[]
NPOI.SS.Formula.FormulaParser.PowerFactor[]
NPOI.SS.Formula.FormulaParser.Term[]
NPOI.SS.Formula.FormulaParser.AdditiveExpression[]
NPOI.SS.Formula.FormulaParser.ConcatExpression[]
NPOI.SS.Formula.FormulaParser.ComparisonExpression[]
NPOI.SS.Formula.FormulaParser.IntersectionExpression[]
NPOI.SS.Formula.FormulaParser.UnionExpression[]
NPOI.SS.Formula.FormulaParser.Parse[]
NPOI.SS.Formula.FormulaParser.Parse[string formula, IFormulaParsingWorkbook workbook, FormulaType formulaType, int sheetIndex, int rowIndex]
NPOI.XSSF.UserModel.XSSFName.set_RefersToFormula[string value]
NPOI.XSSF.UserModel.XSSFSheet.SetAutoFilter[CellRangeAddress range]

class FunctionMetadataReader {

if NETSTANDARD2_0

private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

else

private const String METADATA_FILE_NAME = "functionMetadata.txt";

Changes to

class FunctionMetadataReader {

if NETSTANDARD2_1 || NETSTANDARD2_0

private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

else

private const String METADATA_FILE_NAME = "functionMetadata.txt";

This issue is caused by this bug. But the fix will only be involved in next release. The bad news is that the release time of next release is to be determined.

This bug is a showstopper for me, and I can't downgrade because I'm running net core 3.1 so I need the 2.1 standard. Any way you can push 2.5.3 with this as a patch?

Same here. .NET Core 5, NPOI version 2.5.2, trying to set sheet.SetAutoFilter[new CellRangeAddress[7, Data.Count, 0, 6]];

and I get

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

0

For those having this issue, we are currently using v2.5.1 fine. It doesn't seem to have the problem.

For those having this issue, we are currently using v2.5.1 fine. It doesn't seem to have the problem.

Clarification: v.2.5.1 works with .NET Core 3.1 v2.5.1/v2.5.2 doesn't work with .NET 5

v.2.5.1 works with .NET Core 3.1 and .NET 5 for me. Only 2.5.2 blows chunks.

My Use: ICell cell = row.CreateCell[1]; cell.SetCellType[CellType.Formula]; cell.SetCellFormula["COUNTA[OFFSET[Sheet2!A:A,1,0,COUNTA[Sheet2!A:A]-1]]"];

I have the same problem with .Net 5.0.3 and NPOI 2.5.2.

Code:

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

1

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

2

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

3

And Error: Value cannot be null. [Parameter 'stream']

    class FunctionMetadataReader
    {

# if NETSTANDARD2_1 || NETSTANDARD2_0
        private const String METADATA_FILE_NAME = "NPOI.Resources.functionMetadata.txt";

# else
        private const String METADATA_FILE_NAME = "functionMetadata.txt";

4

Any solution?

Same problem here [core 3.1 => NPO 2.5.2].

My use:

IName namedCell = this._workbook.CreateName[];
namedCell.NameName = "hidden_name";
namedCell.RefersToFormula = "Hidden!$A$1$U$1;

Works fine with 2.5.1

Likewise having an issue with this, .NET Core 3.1 & NPOI 2.5.2 throws this exception for me. I've rolled back to NPOI 2.5.1 and it's working ok.

Chủ Đề