Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

OcxState Failing (reposted, but with more info)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin Westhead - 12 Sep 2003 18:48 GMT
I have generated a signed OCX wrapper for a licenced ActiveX control using
aximp with the /source option, as recommended in Adam Nathan's interop
guide. However, whenever I add an instance of this control to a form and
then save the form I receive the following error:

Code generation for property 'OcxState' failed.
Error was: 'Found a high surrogate char without a following low surrogate at
index: 7.  The input may not be in this encoding, or may not contain valid
Unicode (UTF-16) characters.
Parameter name: chars'

It turns out that this is a problem with the licence string, which contains
the following sequence of characters at the specified index:

0xDAFB, 0xDA8A

Since 0xDAFB is in the Unicode high surrogate range (0xD800-0xDBFF), to be a
well-formed Unicode text string, this should be followed by a low-surrogate
character, i.e. a character in the range 0xDC00-0xDFFF. Unfortunately 0xDA8A
doesn't meet this requirement, and it seems like this is why the exception
is being thrown. I can work around this issue by manually building the
correct licence string with a StringBuilder and then explicitly setting the
licenseKey member using Reflection as part of my initialisation:

 Dim info As FieldInfo = GetType(AxHost).GetField("licenseKey",
BindingFlags.Instance Or BindingFlags.NonPublic)
 AxCtrl = New AxInterop.LibName.AxMyControl()
 info.SetValue(AxCtrl , licenseBuilder.ToString())

Unfortunately this means I cannot add or manipulate the controls at
design-time using the designer, so it's not really a workable solution.

I guess my question (yes, there is a question <g>) is why is the licence
string being validated in this way? It seems like an unnecessary restriction
to me.

Signature

Kevin Westhead

Lion Shi - 15 Sep 2003 09:26 GMT
Hello Kevin,

Thanks for your feedback. And I agree with your opntion, this validation
seems doesn't make sence. I will forward this info to our product group.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ?C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2003 Microsoft Corporation. All rights
reserved.
--------------------
| From: "Kevin Westhead" <kevinw@NOSPAM.i2DOTcoDOTuk>
| Subject: OcxState Failing (reposted, but with more info)
[quoted text clipped - 46 lines]
| string being validated in this way? It seems like an unnecessary restriction
| to me.
Kevin Westhead - 15 Sep 2003 12:07 GMT
> Thanks for your feedback. And I agree with your opntion, this validation
> seems doesn't make sence. I will forward this info to our product group.

Ideally we would like to avoid having to recreate our licence strings (I'm
not even sure how we will do this anyway, such that we avoid the Unicode
surrogate range), so I'd appreciate any advice you can offer to get around
this problem.

Thanks.

Signature

Kevin Westhead

Robert Gruen [MSFT] - 22 Sep 2003 19:05 GMT
Kevin,

I just wanted to let you know that I've taken ownership of answering your
questions and will be researching an answer.  You'll hear from me in a
couple of days.

Thanks!  Robert Gruen
Microsoft, VB.NET

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
| From: "Kevin Westhead" <kevinw@NOSPAM.i2DOTcoDOTuk>
| References: <#EUgKYVeDHA.3708@tk2msftngp13.phx.gbl>
<KXnOUM2eDHA.536@cpmsftngxa07.phx.gbl>
| Subject: Re: OcxState Failing (reposted, but with more info)
| Date: Mon, 15 Sep 2003 12:07:48 +0100
[quoted text clipped - 7 lines]
| NNTP-Posting-Host: host5.i2.co.uk 193.129.24.5
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.interop:18718
| X-Tomcat-NG: microsoft.public.dotnet.framework.interop
[quoted text clipped - 8 lines]
|
| Thanks.
Robert Gruen [MSFT] - 24 Sep 2003 16:22 GMT
Kevin,

I've investigated this with some of the dev's responsible for this
technology and here are our findings:

- There does not appear to be any clear work arounds to avoid calling
System.Text.UTF8Encoding in this scenario.  Currently this is the
implementation of the encoding and the behavior is considered by design.  
However we do have some potential "shots in the dark," that could
potentially have you circumvent this behavior.

- The 1st thing you can try, which works if the control is something you've
written, is to override the implementation of
IClassFactory2::RequestLicKey.   We get the licenseKey from the ActiveX
control using IClassFactory2::RequestLicKey, so if you modify this to
return a value that does have the appropriate high surrogate/low surrogate
order you will be ok. Of course this similar to changing the license key so
you may not want to implement this.

- The only other consideration to changing the functionality so the
encoding is never called is to modify the reflection based solution you
had.  We hadn't thought it through but basically the idea would be to
modify your control such that it can distinguish between design-time and
run-time and have the functionality check for different licenses or no
license at all during design time.

Unfortunately the information above is all we can give you as far as
getting a work around to the current behavior.

Thanks!  Robert Gruen
Microsoft, VB.NET

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
| From: "Kevin Westhead" <kevinw@NOSPAM.i2DOTcoDOTuk>
| Subject: OcxState Failing (reposted, but with more info)
[quoted text clipped - 46 lines]
| string being validated in this way? It seems like an unnecessary restriction
| to me.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.