IUnknown

Hi!

I got a sproc that returns data localized. Its 3 datetime fields returned as nvarchar. They are correctly loaded into a business object, but when the ReportViewer is going to render them to PDF, I get an MDA exception:

A call to PInvoke function 'Microsoft.ReportViewer.Common!Microsoft.ReportingServices.Rendering.ImageRenderer.CompositionPDF+WindowsGDIWrapper::GetGlyphIndicesW' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

How can I resolve this.

Please, post real answers cause I saw this is a repeating problem but no one gave a concise answer.

Many Thanks in advance.


Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

>>Please, post real answers cause I saw this is a repeating problem but no one gave a concise answer.

Um, excuse me but ...

The reason this is hard to resolve and is not resolved the same way in each case is because a lot depends on how you are providing the datetime information to the control as well as what your report definition is using this data for.

Sure you'd like a fast and easy response, and you don't want your time wasted, we understand that <s>. And we don't like to waste our time either.

So please post real (and concise) information:

1. Just in case: Is this being handled in server side processing (RDL) or an RDLC I think an RDLC from what you have said but am not sure.

2. Are nulls ever included in these results

3. Are these fields being displayed in textboxes, and if so what are the expressions and formats you're using

4. Are these fields used in any other expressions in the report, such as aggregates, filters, etc

>L<






Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

IUnknown

Hi there!!!

I understand that maybe its dificult. But as I saw, Its a very consistent problem que exporting to PDF using a LocalReport object with Unicode characters.

With post real answers I tried to ask for answers that are followable or achivable. For example, in one post I found someting like "apply SSSP2" and, ok Sql Server Reporting Services may use the same components as ReportViewer, but what it has to do Sql Server Service Pack 2 and ReportViewer on Visual Studio 2005 . Sorry If I were a little rude or extremely direct.

Now, answering your questions:
1) Its a layered WinForms application. We have a dll for Data Access, another for Business Objects and another for UI. It uses ReportViewer in LocalMode (RDLC) accesing data from collections of Business Objects. There are 2 options that allow the user to export to PDF.

2) Nulls are never included in these results. They are auto-converted to string.Empty.

3) They are displayed in TextBox's but they are all unformated. The sproc return a datetime converted to Thai (for example) as a string (day/monthname/year) and then stored in a string property on a business object.

4) The report has no aggregates, groupings, filters.

Hope this info can help...





Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

hi yes thanks it does help.

So the issue is with the Thai (or whatever) accented characters in the month names

Are you using Unicode fonts in your report consistently A lot of times this type of thing happens because the font that should be used for the PDF (and sometimes there is font mapping involved during the translation to PDF) just doesn't have the correct characters to use.

If you give me an example value to try, and the font you're using, I'll try to repro.

>L<






Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

IUnknown

HI!!!!

These is the data viewed with SQL Server Management Studio.

1_Data.jpg
These 3 fields are filled with something like this:

set language @lenguaje -- Where lenguaje is a string representing the language

SELECT ... operacion_fx.nm_operacion,
(datename(d,operacion_fx.fecha_operacion))+ '-' + (datename(m,operacion_fx.fecha_operacion)) + '-' + .... (datename(yy,operacion_fx.fecha_operacion)) as fecha_operacion,

This is the schema for these data. As you may see these 3 fields are nvarchar.

2_DataTypes.jpg

The font being used is Times New Roman.

Two funny thigs are that if I made a report with a DataSet executing the sproc that returns this data, it shows correctly.

TIA!!!!




Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

OK a couple of things:

1) I can't cut and paste an example with your screen shots <rofl>. I was hoping for a real text example... can you give me the character values for the month names Maybe I can do it that way.

2) I am pretty sure that Times New Roman is not a unicode font. But, to make matters worse, it is a font that is often re-mapped by a conversion or export facility -- and often you don't have a lot of control over how that is done.

I am going to try to explain this -- probably slightly inaccurately -- and also in spite of the explanation not being part of a concise suggestion. So here is the concise suggestion first:

See if the problem go away if you choose a different font First try one that is labeled Unicode. If that works, try another non Times New Roman font and see if it works. If neither works, try a font that explicitly says it has Thai (or whatever) characters on one example language set -- but this is not optimal, so don't try this approach first.

Now for some explanation and background -- which I really think is worth your having in support of the suggestion, and may help you going forward.

Any export facility that creates PDFs and doesn't give you an interface with a lot of export options has to make some decisions for you (because you can create PDFs a whole lot of ways). For example, should it be encrypted or compressed A lot of default choices are made.

One such choice is whether fonts should be embedded, embedded as a subset, or not at all. Another choice is how font choices should be made in various embedding situations.

Suppose the choice is "embed". The PDF must include a glyph or representation of each character -- and internally it may not use exactly the same font that is used for display.

Many fonts have both display versions and print versions. Some fonts don't support all the unicode characters in the print version that they support in the display version. Even though your display may look fine, the PDF export facility may very likely use the print version of a font (PDFs can be optimized for printing, so this is often a good choice).

In the process of choosing a print version the export facility needs to say "what exact font table should I be looking in " And "Times New Roman" is a common font description that may resolve to a lot of different answers to that particular question.

I hope this helps, and I hope my suggestion works for you. If it does not, and if you supply actual character information, as I said, I will try to repro and help further.

>L<






Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

One other thing I thought of -- since the cols are nvarchar is it possible that some of the values do not yield real dates IOW, if you do ISDATE(...) on this field, is this result ever 0

(Got the repro situation handled now -- sorry I missed what language we were in (meaning: tsql) when looking at your language variable ..)

>L<






Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

IUnknown

Hi Lisa!!!

Explanation was very good. Now that's what I was talking about.

I copied the values to a Excel 2003 Worksheet. Hope it helps. If you need anymore info please let me know.

DataValues.xls

With the fonts, I downloaded some Thai and Turkish fonts and in both cases it didnt worked.

I dont remember if I told you, but, I made a quick example using the same sproc but using a DataSet, a DataAdapter and dragged the fields from the Data Sources window. It worked. I think that maybe becuase Im reading those fields with a DbDataReader and passing them to a class (Business Object) maybe Im not stating that they are unicode strings (the fields I use are of C# type string).

I hope that you maybe know something about, cause its kind of weird that in my application (using DbDataReader.GetString() to get data and put it in string fields) dont work and in a simple test (DataSet + DataAdapter with Fill) it works.

Thanks!!!




Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

Hi again,

I can't get through to your link -- which looks like this under the filename:

http://www.scisa.com.mx/Tmp/http://www.scisa.com.mx/Tmp/DataValues.xls -- is that correct No, it can't be. However, duh, it's pretty obvious what you meant to type .

Okay, those values look exactly like what I generated -- FWIW I did the following:

Code Snippet

SET LANGUAGE Thai
SELECT datename(d,GETDATE())+ '-' +
datename(m,GETDATE()) + '-' +
datename(yy,GETDATE()) as FakeDate

... when it didn't crash I tried this as well:


Code Snippet

SET LANGUAGE Thai
SELECT *,CAST( datename(d,last_edit)+ '-' +
datename(m,last_edit) + '-' +
datename(yy,last_edit) AS NVARCHAR(30))
COLLATE THAI_BIN AS FakeDate FROM Recipient

... just to make sure to try everything. I tried two different report servers and both XP and Vista and, as expected, got different results from different fonts, and also different results in display versus PDF for certain fonts. For Times Roman, I could see thai chars on the screen but the PDF export looked like -- whereas the thai characters were preserved in Tahoma. However, nothing crashed.

OK so far This was server mode -- I have more RDLs lying around for test purposes than RDLCs .

Then I tried localmode (RDLCs). Again I used a statement like this:

Code Snippet


SET LANGUAGE Thai
SELECT *,CAST( datename(d,last_edit)+ '-' +
datename(m,last_edit) + '-' +
datename(yy,last_edit) AS NVARCHAR(30))
COLLATE THAI_BIN AS FakeDate FROM Recipient

... I had the same results: some fonts had matching behavior in display and print sets (Times New Roman being notably bad, Tahoma being notably good). But nothing crashed. (I'm assuming that by "did not work" you mean "it crashed" with that glyph lookup error, rather than simply seeing characters where the data should be in the output, right )

I think you must be right that there is something about what you're doing with the dbReader that is misinterpreting the unicode values for these characters. At some point -- and yes GetString() might be it -- you're mis-encoding something or the PDF rendering extension is misunderstanding what you're giving it. But there isn't really any way for me to test this any further without your exact code.

If you can post or e-mail a simple set of steps to repro for getting your crash, I will try to figure out how to re-encode (or whatever) at the point of failure if I have the time. (This being Labor Day <sigh>, I had time to get this far. But tomorrow starts a new crunch.) Other than that, here is what I suggest you do:

Try GetChars() or GetBytes() instead of GetString(). You will probably have more luck coaxing the data into the correct encoding if you do. I'm not sure how much effort this will be for you -- and generally this is a PITA -- but it has a high probability of being the point of failure, so anything you can do to change the code at this point might at least change the behavior and move you into a diagnostic, rather than crash, mode.

HTH,

>L<






Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

IUnknown

IM SO EMBARRASED!!!! The data is at DataValues.xls




Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

IUnknown

I didnt remember that You were prox. to labor date. Im on financial products development so WE DONT HAVE LABOR DAYS hahaha .

Anyway, I will try to slim down a version of the code and send you the correct download link (I hope ).

Thank you very much, if I can make something in regard please just ask...




Re: Visual Studio Report Controls PInvokeImbalance when LocalReport.Render("PDF"...

Lisa Nicholls

I did say that I figured out the link to your XLS, didn't I <s>

By mentioning Labor Day I meant: this is pretty much the *only* day I would have had time to do this...

Try my suggestions (work on changing your code slightly to use GetChars or GetBytes rather than GetString) first.

If you can't figure it out or if you can't see any changed behavior by tweaking this part of your code, then maybe it will be worth putting the extra effort into slimming down your code for a reproducible case, and I will try to make an extra effort to help you nail this, too.

>L<