@@ -42,7 +42,7 @@ [ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
4242private string installedFilePath ;
4343private string minorVersionNumber ;
4444private string majorVersionNumber ;
45- private string lcid ;
45+ private readonly int lcid ;
4646 #endregion
4747
4848 #region properties
@@ -76,7 +76,7 @@ public string InstalledFilePath
7676}
7777
7878[ SuppressMessage ( "Microsoft.Naming" , "CA1709:IdentifiersShouldBeCasedCorrectly" , MessageId = "LCID" ) ]
79- public string LCID
79+ public int LCID
8080{
8181get { return lcid ; }
8282}
@@ -133,7 +133,7 @@ internal ComReferenceNode(ProjectNode root, ProjectElement element)
133133
134134this . majorVersionNumber = this . ItemNode . GetMetadata ( ProjectFileConstants . VersionMajor ) ;
135135this . minorVersionNumber = this . ItemNode . GetMetadata ( ProjectFileConstants . VersionMinor ) ;
136- this . lcid = this . ItemNode . GetMetadata ( ProjectFileConstants . Lcid ) ;
136+ this . lcid = int . Parse ( this . ItemNode . GetMetadata ( ProjectFileConstants . Lcid ) ) ;
137137this . SetProjectItemsThatRelyOnReferencesToBeResolved ( false ) ;
138138this . SetInstalledFilePath ( ) ;
139139}
@@ -161,14 +161,15 @@ internal ComReferenceNode(ProjectNode root, VSCOMPONENTSELECTORDATA selectorData
161161this . typeGuid = selectorData . guidTypeLibrary ;
162162this . majorVersionNumber = selectorData . wTypeLibraryMajorVersion . ToString ( CultureInfo . InvariantCulture ) ;
163163this . minorVersionNumber = selectorData . wTypeLibraryMinorVersion . ToString ( CultureInfo . InvariantCulture ) ;
164- this . lcid = selectorData . lcidTypeLibrary . ToString ( CultureInfo . InvariantCulture ) ;
164+ this . lcid = ( int ) selectorData . lcidTypeLibrary ;
165165
166166// Check to see if the COM object actually exists.
167167this . SetInstalledFilePath ( ) ;
168168// If the value cannot be set throw.
169169if ( String . IsNullOrEmpty ( this . installedFilePath ) )
170170{
171- throw new ArgumentException ( ) ;
171+ var message = string . Format ( SR . GetString ( SR . ReferenceCouldNotBeAdded , CultureInfo . CurrentUICulture ) , selectorData . bstrTitle ) ;
172+ throw new InvalidOperationException ( message ) ;
172173}
173174}
174175
@@ -195,14 +196,15 @@ internal ComReferenceNode(ProjectNode root, string filePath)
195196this . typeGuid = typeAttr . guid ;
196197this . majorVersionNumber = typeAttr . wMajorVerNum . ToString ( CultureInfo . InvariantCulture ) ;
197198this . minorVersionNumber = typeAttr . wMinorVerNum . ToString ( CultureInfo . InvariantCulture ) ;
198- this . lcid = typeAttr . lcid . ToString ( CultureInfo . InvariantCulture ) ;
199+ this . lcid = typeAttr . lcid ;
199200
200201// Check to see if the COM object actually exists.
201202this . SetInstalledFilePath ( ) ;
202203// If the value cannot be set throw.
203204if ( String . IsNullOrEmpty ( this . installedFilePath ) )
204205{
205- throw new ArgumentException ( ) ;
206+ var message = string . Format ( SR . GetString ( SR . ReferenceCouldNotBeAdded , CultureInfo . CurrentUICulture ) , filePath ) ;
207+ throw new InvalidOperationException ( message ) ;
206208}
207209}
208210finally
@@ -281,21 +283,20 @@ internal ComReferenceNode(ProjectNode root, string filePath)
281283[ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Globalization" , "CA1308:NormalizeStringsToUppercase" ) ]
282284private ProjectElement GetProjectElementBasedOnInputFromComponentSelectorData ( )
283285{
284-
285286ProjectElement element = new ProjectElement ( this . ProjectMgr , this . typeName , ProjectFileConstants . COMReference ) ;
286287
287288// Set the basic information regarding this COM component
288289element . SetMetadata ( ProjectFileConstants . Guid , this . typeGuid . ToString ( "B" ) ) ;
289290element . SetMetadata ( ProjectFileConstants . VersionMajor , this . majorVersionNumber ) ;
290291element . SetMetadata ( ProjectFileConstants . VersionMinor , this . minorVersionNumber ) ;
291- element . SetMetadata ( ProjectFileConstants . Lcid , this . lcid ) ;
292+ element . SetMetadata ( ProjectFileConstants . Lcid , this . lcid . ToString ( ) ) ;
292293element . SetMetadata ( ProjectFileConstants . Isolated , false . ToString ( ) ) ;
293294
294295// See if a PIA exist for this component
295296TypeLibConverter typelib = new TypeLibConverter ( ) ;
296297string assemblyName ;
297298string assemblyCodeBase ;
298- if ( typelib . GetPrimaryInteropAssembly ( this . typeGuid , Int32 . Parse ( this . majorVersionNumber , CultureInfo . InvariantCulture ) , Int32 . Parse ( this . minorVersionNumber , CultureInfo . InvariantCulture ) , Int32 . Parse ( this . lcid , CultureInfo . InvariantCulture ) , out assemblyName , out assemblyCodeBase ) )
299+ if ( typelib . GetPrimaryInteropAssembly ( this . typeGuid , Int32 . Parse ( this . majorVersionNumber , CultureInfo . InvariantCulture ) , Int32 . Parse ( this . minorVersionNumber , CultureInfo . InvariantCulture ) , this . lcid , out assemblyName , out assemblyCodeBase ) )
299300{
300301element . SetMetadata ( ProjectFileConstants . WrapperTool , WrapperToolAttributeValue . Primary . ToString ( ) . ToLowerInvariant ( ) ) ;
301302}
@@ -325,7 +326,7 @@ private void SetProjectItemsThatRelyOnReferencesToBeResolved(bool renameItemNode
325326if ( String . Compare ( MSBuildItem . GetMetadataValue ( reference , ProjectFileConstants . Guid ) , this . typeGuid . ToString ( "B" ) , StringComparison . OrdinalIgnoreCase ) == 0
326327&& String . Compare ( MSBuildItem . GetMetadataValue ( reference , ProjectFileConstants . VersionMajor ) , this . majorVersionNumber , StringComparison . OrdinalIgnoreCase ) == 0
327328&& String . Compare ( MSBuildItem . GetMetadataValue ( reference , ProjectFileConstants . VersionMinor ) , this . minorVersionNumber , StringComparison . OrdinalIgnoreCase ) == 0
328- && String . Compare ( MSBuildItem . GetMetadataValue ( reference , ProjectFileConstants . Lcid ) , this . lcid , StringComparison . OrdinalIgnoreCase ) == 0 )
329+ && String . Compare ( MSBuildItem . GetMetadataValue ( reference , ProjectFileConstants . Lcid ) , this . lcid . ToString ( ) , StringComparison . OrdinalIgnoreCase ) == 0 )
329330{
330331string name = MSBuildItem . GetEvaluatedInclude ( reference ) ;
331332if ( Path . IsPathRooted ( name ) )
@@ -365,9 +366,16 @@ private void SetInstalledFilePath()
365366this . typeName = typeLib . GetValue ( string . Empty ) as string ;
366367}
367368// Now get the path to the file that contains this type library.
368- using ( RegistryKey installKey = typeLib . OpenSubKey ( string . Format ( CultureInfo . InvariantCulture , @"{0}\win32" , this . lcid ) ) )
369+
370+ // lcid
371+ // The hexadecimal string representation of the locale identifier (LCID).
372+ // It is one to four hexadecimal digits with no 0x prefix and no leading zeros.
373+ using ( RegistryKey installKey = typeLib . OpenSubKey ( string . Format ( CultureInfo . InvariantCulture , @"{0:X}\win32" , this . lcid ) ) )
369374{
370- this . installedFilePath = installKey . GetValue ( String . Empty ) as String ;
375+ if ( installKey != null )
376+ {
377+ this . installedFilePath = installKey . GetValue ( String . Empty ) as String ;
378+ }
371379}
372380}
373381}