Skip to content
New issue

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

Error BC30512 Option Strict On tripped in VS2015 and not in VS2013 #13314

Closed
isburns opened this issue Aug 23, 2016 · 10 comments
Closed

Error BC30512 Option Strict On tripped in VS2015 and not in VS2013 #13314

isburns opened this issue Aug 23, 2016 · 10 comments
Assignees
Labels
Area-Compilers Language-VB Resolution-By Design The behavior reported in the issue matches the current design
Milestone

Comments

@isburns
Copy link

isburns commented Aug 23, 2016

Version Used:
Visual Studio Community 2015, Version 10.0.25424.00 Update 3 (doesn't work)
Visual Studio Professional 2013, Version 10.0.40629.00 Update 5 (works)

Steps to Reproduce:
Using the ArcObjects SDK for the Microsoft .NET Framework for ArcGIS 10.4 and targeting 4.5.2 of the .NET Framework, the following line of code results in error BC30512 Option Strict On Disallows implicit conversions from 'IPolygon' to 'IGeometry'.
Dim bufferedPolygon As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Polygon

Polygon is the class interface of the COM coclass of the same name. This behavior is inconsistently, and perhaps improperly enforced, because other class interfaces in the same library both trigger and do not trigger the error. All examples given are widening conversions where the class interface/coclass instantiated inherits from the Geometry abstract class. Additionally, none of the examples given trip errors in Visual Studio 2013 targeting .NET Framework 4.5.2 with the same ArcObjects SDK for ArcGIS 10.4.

This also triggers the error.
Dim aPath As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Path
Dim tri As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Triangles

This does not.
Dim aSphere As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Sphere
Dim pt As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Point
Dim aRay As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Ray

Viewing the OMDs (see attached), a pattern initially appeared where the instantiating class interfaces (Point, Ray, Sphere) that are first descendents of the Geometry abstract parent class do not trigger the error and instantiating class interfaces (Polygon, Path) that inherit from another abstract class which inherits from the Geometry abstract parent class do trigger the error. However, Triangles is a first descendent of Geometry and it fails, so the lineage does not tell the whole story. The COM to .NET type conversion of the ArcObjects documentation is relevant: Using ArcObjects (COM-Based in .NET (ArcObjects .NET 10.4 SDK).

GeometryObjectModel.pdf

@jaredpar
Copy link
Member

Thanks for reporting this. We will take a look at this issue.

@AlekseyTs AlekseyTs added the Need More Info The issue needs more information to proceed. label Sep 16, 2016
@AlekseyTs
Copy link
Contributor

@isburns Please provide the library that defines the types used. Thanks.

@AlekseyTs
Copy link
Contributor

@isburns I am closing this issue due to the lack of the data required for investigation. Please reactivate it once you are ready to provide access to the library. Thanks.

@isburns
Copy link
Author

isburns commented Sep 21, 2016

Apologies for not responding sooner, I was out of the office for a few days when you asked for the library. I am trying to attach it now, but I get the message "Unfortunately, we don't support that file type. Try again with a PNG, GIF, JPG, DOCX, PPTX, XLSX, TXT, PDF, or ZIP." The DLL is in a ZIP file when I try to upload it.

Shea

@AlekseyTs
Copy link
Contributor

You can try changing extension before zipping it up, using external file sharing service, or disassembling the library with ILDASM into a TXT file and attaching that in a ZIP. An original DLL would be preferred, though.

@isburns
Copy link
Author

isburns commented Sep 21, 2016

Renaming the file before zipping it did not work, however renaming the zip file itself did. You will need to download the file, then change the .txt to .zip.

ESRI.ArcGIS.Geometry.txt

@AlekseyTs
Copy link
Contributor

@isburns Thanks. It looks like ESRI.ArcGIS.Geometry.dll has another dependency, ESRI.ArcGIS.System. Could you please attach all the dependencies required to compile the following code without errors about missing type definitions?

Module Module1
    Sub Main()
        Dim bufferedPolygon As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Polygon
        Dim aPath As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Path
        Dim tri As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Triangles
        Dim aSphere As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Sphere
        Dim pt As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Point
        Dim aRay As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Ray
    End Sub
End Module

@isburns
Copy link
Author

isburns commented Sep 22, 2016

Sorry I missed that, I confirmed that it is the only other required reference. I renamed the extension of the zip file again, so you'll need to change it back from .txt to .zip once you download it.

ESRI.ArcGIS.System.txt

@AlekseyTs
Copy link
Contributor

With Option Strict On, Roslyn reports the following errors:

(3) : error BC30512: Option Strict On disallows implicit conversions from 'Polygon' to 'IGeometry'.

        Dim bufferedPolygon As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Polygon
                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(4) : error BC30512: Option Strict On disallows implicit conversions from 'Path' to 'IGeometry'.

        Dim aPath As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Path
                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(5) : error BC30512: Option Strict On disallows implicit conversions from 'Triangles' to 'IGeometry'.

        Dim tri As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Triangles
                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Native compiler compiles the code without the errors.

@AlekseyTs AlekseyTs reopened this Sep 22, 2016
@AlekseyTs AlekseyTs added Language-VB and removed Need More Info The issue needs more information to proceed. labels Sep 22, 2016
@AlekseyTs
Copy link
Contributor

This is an intentional behavior change, a bug fix in Roslyn. All three types (ESRI.ArcGIS.Geometry.Polygon, ESRI.ArcGIS.Geometry.Path and ESRI.ArcGIS.Geometry.Triangles) are interfaces and none of them implement ESRI.ArcGIS.Geometry.IGeometry (directly or indirectly). If I remember correctly, VS2013 compiler was inconsistent in deciding what should be the result type of "Newing" an interface, in some cases it was a CoClass, in other cases it was an interface (I believe one of the scenarios like that was a scenario with an object initializer). It was decided that the correct behavior of the compiler is to always use the interface as the result type of "Newing" an interface. Given that, Roslyn behavior is By Design.

@AnthonyDGreen, @jaredpar Please, let me know if you disagree with the resolution.

@AlekseyTs AlekseyTs added Resolution-By Design The behavior reported in the issue matches the current design and removed Bug labels Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Language-VB Resolution-By Design The behavior reported in the issue matches the current design
Projects
None yet
Development

No branches or pull requests

3 participants