OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

VS 2017 15.4.2 Broken client #985

Closed a-teece closed 6 years ago

a-teece commented 6 years ago

Using either method to create an Odata client in VS 2017 isn't working With the OData Connected Service extension installed it still doesn't show in Add Connected Service. So cannot use this method.

When trying to use the OData Client Code Generator the code that is produced is invalid. It wont run until I add additional references such as System.Runtime. Even then at runtime it has errors that "The schema element ‘NavigationProperty’ was not expected in the given context". I dont believe the EDMX is invalid and even if it were ignore invalid elements is set to true in the .tt file, but it doesn't seem to actually have an effect.

Reproduce steps

  1. Simply install the "OData Connected Service" v0.3
  2. Right click the project and Add Connected Service
  3. Only Azure Storage is shown.

For method 2 using the tt template:

  1. install the "OData v4 Client Code Generator"
  2. Add an OData client
  3. Set the metadata URL and run the tool
  4. See the errors about missing references

Both tests were attempted using both VB and C# projects for .Net 4.6.1

Expected result

Connected Service is shown and OData client code is generated

Actual result

Connected Service is not shown. Using the TT method wont work without editing. Even after getting the template to run the produced code wont run.

mtroth-microsoft commented 6 years ago

The TT method requires you to provide the location of the file. Did running the generator result in a valid class file? that is, can you build your project after generating the classes? I walked through the steps in method 2 and was able to generate a proper set of client classes from the local csdl.

a-teece commented 6 years ago

I put a valid URL in. But that isn't the problem. The TT file won't run because references are missing such as System.Runtime. The references do appear to be in the Github source, but not the one deployed in the extension. So it definitely seems broken in the released version.

If i manually fix my version with additional references, I can get the TT file to run and it produces a valid class. But then at runtime I get a problem with an exception "The schema element ‘NavigationProperty’ was not expected in the given context" - even though IgnoreUnexpectedElementsAndAttributes is true. I think this is because the generated code uses Parse instead of TryParse in LoadModelFromString. As such it always throws an error.

Just looks like the "released" extension on the market place simply doesn't work correctly - I'm looking for alternative OData clients now too as this doesn't look usable. Looking in Github the TT include file has had changes to rename classes, so that doesn't work with the released NuGet Client package.

a-teece commented 6 years ago

Really easy to reproduce. Use VS 2017 15.4.2. with the extension installed. In a blank vb.net console app try to add a "Connected Service". It doesn't show OData, just Azure Storage. So try to use the code generator extension. I think any metadata document will cause a problem with the references, but even if you fix those manually I couldn't use the OData service at https://staging.uipath.com/odata/$metadata - even though I think it is valid and I had the IgnoreUnexpectedElementsAndAttributes option set to true.

Any help greatly appreciated.

a-teece commented 6 years ago

Sorry. I just noticed you said "I walked through the steps in method 2 and was able to generate a proper set of client classes from the local csdl.".

Was that using the released TT file in the extension on the market place, or was that using the tt file from Github?

Neither works for me, but they are different.

mtroth-microsoft commented 6 years ago

ah sorry I didn't see that you are using vb.net. This is a known issue.

AlanWong-MS commented 6 years ago

@a-teece, regarding your two issues: 1) As @mtroth-microsoft mentioned, this one's a known issue and it seems that not all users experience it. Some have repro'd on C# side and it seems to have come up recently with VS2017. I'm currently trying to engage the Visual Studio team to further investigate this.

2) I'm currently working on this issue and will be releasing OData v4 Client Code Generator that's compatible with VS2017. This should happen within a week or two.

a-teece commented 6 years ago

Alan, Good to know that it's a known issue and I shouldn't have tried to use it with VS 2017 yet. Last night I got it to should in "Connected Services" once in a C# project. But reloading VS again and it went. No idea why it suddenly appeared then went again :(

Regarding the code produced by the templates I think there is a bug in the LoadModelFromString method. It always uses parse, so any errors it detects cause exceptions rather than being ignored. If IgnoreUnexpectedElementsAndAttributes is set should it not use TryParse so that unexpected elements and attributes can be ignored? Even then I dont think my metadata does have an unexpected element so there may be a bug in the parsing too.... but I'm still trying to validate that.

AlanWong-MS commented 6 years ago

Fixed with #1150.