I've been using the .NET MessagingToolkit.QRCode library for some time on my websites in order to generate QR codes with custom images on top and until now I have had no problems at all with this library.
Recently, the data I need to encode has gotten larger as a result of system growth and attempting to encode this data within a QR code has been causing internal "index out of range" exceptions within the Encode method of the QRCodeEncoder class.
Through testing I have noted that the maximum number of characters this method appears to accept is 86 and anything greater than this will throw the exception. Changing the encoding type of the string passed in does not help.
I did note that the version of the library I was using was out of date, however, updating to the latest version also did not solve the problem.
Has anyone else experienced this issue with the library and found a solution? Alternatively, is there another library I could use which does not have such problems?
The exception details are below:
2012-10-01 17:39:52,098 Error: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MessagingToolkit.QRCode.Codec.QRCodeEncoder.divideDataBy8Bits(Int32[] data, SByte[] bits, Int32 maxDataCodewords)
at MessagingToolkit.QRCode.Codec.QRCodeEncoder.calQrcode(Byte[] qrcodeData)
at MessagingToolkit.QRCode.Codec.QRCodeEncoder.Encode(String content, Encoding encoding)
at MessagingToolkit.QRCode.Codec.QRCodeEncoder.Encode(String content)
On the official page for that library there is a short description of solution for your problem: http://platform.twit88.com/news/60. I don't know if that would fix your problem though. I would find the source code of the library and debug through it to see the reason for the error.
hm... can't find the source code anywhere. So get in touch with the authors and ask them.
If that does not work out, I would change the library to something else. I have used QrCode.Net with MVC successfully and have some sample code how to integrate it to MVC, if you like.
I know this post is a little old but I ran into the same issue and discovered I had an illegal character in my string ( ” ) which the QR code did not recognize. Replaced this with a regular quote ( " ) and it worked fine.
I got same problem
QRCodeEncoder qrCE = new QRCodeEncoder();
qrCE.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
qrCE.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
qrCE.QRCodeVersion = 1;
picQRCode.Image = qrCE.Encode(memBarcodeDataForPrint.Text, System.Text.Encoding.UTF8);
I changed following line
qrCE.QRCodeVersion = 1;
like
qrCE.QRCodeVersion = 0;
It solved.
I experienced the same problem. However I found that creating a new instance of the encoder each time I called the Encode method solved the issue.
Same problem but when change version to 0 it working.
Related
Right now I am working on a project where I am converting a VB.NET code to C#.
I have used https://converter.telerik.com/, which I have heard is quite accurate. Which it mostly is, but now I have approached a error: non-invocable member 'dataset.tables' cannot be used like a method.
This is my first converting ever so I have it quite hard to see what is wrong with just this line of code.
Heres the VB.NET sample:
RcdCount = da.Tables("pubs").Rows.Count.ToString()
Here is the C# sample:
RcdCount = da.Tables("pubs").Rows.Count.ToString();
As you can see, the only change that is made is the ";" at the end.
How do I solve this?
As it seems, Tables is an indexer, therefore square brackets must be used:
RcdCount = da.Tables["pubs"].Rows.Count.ToString();
I see you already found the answer you were looking for. But if you still want to take a look, I tested the code sample on this site and it translated correctly.
carlosag.net
I've run into a peculiar case where I get the following error when creating certain types of string:
Unexpected error writing debug information -- 'Error HRESULT E_FAIL has been returned from a call to a COM component.'
This error is not new to Stack Overflow (see this question and this question), but the problems presented have nothing to do with this one.
For me, this is happening when I create a const string of a certain length that includes a null-terminating character (\0) somewhere near the beginning.
To reproduce, first generate a string of appropriate length, e.g. using:
var s = new string('a', 3000);
Grab the resulting string at runtime (e.g. Immediate Window or by hovering over the variable and copying its value). Then, make a const out of it:
const string history = "aaaaaa...aaaaa";
Finally, put a \0 in there somewhere:
const string history = "aaaaaaaaaaaa\0aa...aaaaa";
Some things I noticed:
if you put the \0 near the end, the error doesn't happen.
Reproduced using .NET Framework 4.6.1 and 4.5
Doesn't happen if the string is short.
Edit: even more precious info available in the comments below.
Any idea why this is happening? Is it some kind of bug?
Edit: Bug filed, including info from comments. Thanks everybody.
I'll noodle about this issue a little bit. This issue occurs both in VS2015 and earlier versions. So nothing directly to do with the C# compiler itself, this goes wrong in the ISymUnmanagedWriter2::DefineConstant2() implementation method. ISymUnmanagedWriter2 is a COM interface, part of the .NET infrastructure that all compilers use. And used both by Roslyn and the legacy C# compiler.
The comments in the Roslyn source code (actually dates back to the CCI project) that uses the method are illuminating enough, that there is trouble with this method was discovered before:
// EDMAURER If defining a string constant and it is too long (length limit is undocumented), this method throws
// an ArgumentException.
// (see EMITTER::EmitDebugLocalConst)
try
{
this.symWriter.DefineConstant2(name, value, constantSignatureToken);
}
catch (ArgumentException)
{
// writing the constant value into the PDB failed because the string value was most probably too long.
// We will report a warning for this issue and continue writing the PDB.
// The effect on the debug experience is that the symbol for the constant will not be shown in the local
// window of the debugger. Nor will the user be able to bind to it in expressions in the EE.
//The triage team has deemed this new warning undesirable. The effects are not significant. The warning
//is showing up in the DevDiv build more often than expected. We never warned on it before and nobody cared.
//The proposed warning is not actionable with no source location.
}
catch (Exception ex)
{
throw new PdbWritingException(ex);
}
Swallowing exceptions, tsk, tsk. It dies on the last catch clause in your case. They did dig a little deeper to reverse-engineer the string length problem:
internal const int PdbLengthLimit = 2046; // Empirical, based on when ISymUnmanagedWriter2 methods start throwing.
Which is fairly close to where the \0 starts throwing, I got 2034. Nothing much that you or anybody else here can do about this of course. All you can reasonably do is report the bug at connect.microsoft.com. But hopefully you see the writing on the wall, the odds that it will get fixed are rather small. This is code that nobody maintains anymore, it now has 'undocumented' status and judging from other comments this goes back long before .NET. Not Ed Maurer either :)
Workaround ought to be easy enough, glue this string together at runtime.
I was able to repro the issue as coded. Then I changed the declaration to:
const string history = #"aaa\0aaa...lots and lots of aaa...aaa";
Tried again and it compiles just fine.
I try to save/serialize a Lua state. I know, that I had to save/serialize all globals, which I find in _G, but didn't know how to save/serialize the LuaFunctions I find. I tried to use string.dump, but that delivers only a string with the Lua signature (5 bytes with LuaQ).
The function string.dump works, because if I call
lua.DoString("print(string.len(string.dump(CountItems)))");
I get 409 instead of 5 as the length of the string. So the dump works correct. It could be a problem in LuaInterface.
Is there someone out there, how realized a serialization of a Lua state via LuaInterface?
Best regards,
Dirk
PS: I'm using KopiLua 5.1.4 with LuaInterface 2.0.4 on VS 2010 C# Express.
Solved.
The problem was, that the binary chunk, which string.dumpreturns, was handled as a string. So it was cut at the first null byte in the string, which was after 5 bytes. Changed the call of DoString, so that it handles byte arrays correct.
I have had a hard time getting and answer to this and i would really , really appreciate some help on this.
i have been on this for over 2 weeks without headway.
i want to use c# to add a line of stock data to amibroker but i just cant find a CLEAR response on how to instantiate it in C#.
In VB , I would do it something like;
Dim AmiBroker = CreateObject("Broker.Application")
sSymbol = ArrayRow(0).ToUpper
Stock = AmiBroker.Stocks.Add(sSymbol)
iDate = ArrayRow(1).ToLower
quote = Stock.Quotations.Add(iDate)
quote.Open = CSng(ArrayRow(2))
quote.High = CSng(ArrayRow(3))
quote.Low = CSng(ArrayRow(4))
quote.Close = CSng(ArrayRow(5))
quote.Volume = CLng(ArrayRow(6))
The problem is that CreateObject will not work in C# in this instance.
I found the code below somewhere online but i cant seem to understand how to achieve the above.
Type objClassType;
objClassType = Type.GetTypeFromProgID("Broker.Application");
// Instantiate AmiBroker
objApp = Activator.CreateInstance(objClassType);
objStocks = objApp.GetType().InvokeMember("Stocks", BindingFlags.GetProperty,null, objApp, null);
Can anyone help me here?
Thanks
The VB code uses something called late binding against a "COM IDispatch" compatible component. Late binding is not supported by C# (up to C# version 3). The C# compiler only compiles code it knows how bind to (called early bind).
To do what you want to do, it would be easier to generate a proxy dll via Visual Studio - select add reference on a project, then select the tab COM, and then search for that ami broker component in the list. This will generate a proxy dll which you can program against using similar code as the one you have showed for VB.
In C# 3.0, you'll discover that you sometimes have to use Type.Missing and that you have to do some additional explicit casting, even though you'd think that it doesn't seem logical.
C# 4.0 has something called dynamic, which allows you to write much cleaner code when accessing COM components.
See my answer here for the code:
https://stackoverflow.com/a/20101274/1581495
I actually use this method now. I save text files from MetaTrader then import them realtime into AmiBroker. Doing it this way is essentially like importing quotes using the ASCII import, so you'll need to make sure that you prepare your import format file. For me, a line of sample data looks like this:
EURAUD,20170607,00:00:00.4885,1.50174,1.50231,1 //Symbol, Date, Time (HH:MM:SS.tttt), Bid, Ask, Volume
I use the default.format file, which looks like this:
$FORMAT TICKER,DATE_YMD,TIME,CLOSE,AUX1,VOLUME
$SEPARATOR ,
$AUTOADD 0
$BREAKONERR 0
$SKIPLINES 0
Find the guide and some examples here on importing and formats:
https://www.amibroker.com/guide/d_ascii.html
EDIT: this might also help with importing
http://www.amibroker.com/kb/2016/01/23/how-to-create-custom-import-definition-for-ascii-importer/
With the NAudio library I'm trying to mix some audio using a WaveMixerStream32 so I'm using WaveChannel32 to feed it the streams in the proper format. I've got an exception with the following message:
Offset and length were out of bounds
for the array or count is greater than
the number of elements from index to
the end of the source collection.
The minimum example I could make that also throw that error didn't include WaveMixerStream32 at all with took me to the conclusion that the problem was in how I'm using WaveChannel32. The code is this:
var audio = new WaveFileReader(OriginalAudioFileName);
var audio32 = new WaveChannel32(new WaveFileReader(OriginalAudioFileName));
WaveFileWriter.CreateWaveFile(PublicAudioFileName + "audio.wav", audio);
WaveFileWriter.CreateWaveFile(PublicAudioFileName + "audio32.wav", audio32);
audio.wav is generated just fine. audio32.wav is 58 bytes and that line thrown the exception.
What is wrong?
Yes, this is a bug in NAudio. Thanks for reporting it. I've checked in a fix (was a problem with WaveChannel32.GetSourceBuffer). You also need to know that you must set PadWithZeroes to false on your WaveChannel32 before calling WaveFileWriter.CreateWaveFile or you will create a never-ending WAV file, slowly filling up your hard disk.
I got a repro pretty easily. This looks like a basic bug in WaveChannel32.Read(), it doesn't handle .wav files with multiple channels properly. The numBytes argument looks like the size of the file, not the stream.
Let the project owner know. You'll add your issue to a rather long list though.