OData / lab

This repository is for exploring new ideas and developing early prototypes of various OData stacks.
Other
48 stars 59 forks source link

Adding OData Connected Service to the project failed: Value cannot be null #64

Closed rendmath closed 6 years ago

rendmath commented 6 years ago

We are converting a VS2015 solution using WCF Data Services to VS2017. The web service itself seems to be working fine, but the database model has evolved and we now need to update our OData service reference.

Visual Studio displays an error message, warning us that "The specified OData API cannot be updated because OData APIs are now only supported with Connected Services". We downloaded the connected services extensions available here : https://marketplace.visualstudio.com/items?itemName=laylaliu.ODataConnectedService.

But we can't seem to generate a new OData client for any projet, even a new simple console application. The "OData Connected Service" wizard invariably fails in the "Finish" step with this error message: "Adding OData Connected Service to the project failed: Value cannot be null. Parameter name: path1".

OData Connected Service version: 0.3.0 Visual Studio version: 2017 Enterprise 15.3.3 .NET Framework version: 4.6.1 WCF Data Services versions (server-side):

Here is the $metadata for our service: $metadata.zip

rendmath commented 6 years ago

We have updated our NuGet packages to the latest versions available, but the problem stays the same: WCF Data Services versions (server-side):

black78 commented 6 years ago

VS 2017 15.3.3 same problem: Adding Nuget Packages Error:Adding OData Connected Service to the project failed: Value cannot be null. Parameter name: path1

nla-brandonjames commented 6 years ago

I also get this error. This is after applying the fix @Gabee01 implemented in PR #67 in order to get the metadata without credentials. This is a continuation of issue #56. It also happens if I get the definitions from an edmx file.

nla-brandonjames commented 6 years ago

I ran this project on debug and I found that it pulls null at Line 31 on V3CodeGenDescriptor.cs. The path is referring to the WCF install location.

nla-brandonjames commented 6 years ago

I had to dig through my Windows registry to find out what the issue was. So, CodeGeneratorUtils accesses the Windows Registry to try to figure out where the install location of WCF Services is. On my machine, neither the "SOFTWARE\Wow6432Node\Microsoft\Microsoft WCF Data Services\VS 2014 Tooling\" nor the "SOFTWARE\Microsoft\Microsoft WCF Data Services\VS 2014 Tooling\" path existed in the registry. So I found out the key that referred to the actual install location of WCF Data Services on my machine. It was "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services\5.6\". But I couldn't figure out how to get the code to read the registry path so I just hard-coded the value of InstallLocation from that myself so code gen would work. It was "C:\Program Files (x86)\Microsoft WCF Data Services\5.6". Hopefully you guys can find a more elegant fix for this!

AlanWong-MS commented 6 years ago

@nla-brandonjames we're trying to consolidate all the issues people are coming across on this project. After you modified the registry, have you come across new issues?

nla-brandonjames commented 6 years ago

@AlanWong-MS I did not modify the registry, I just read it to try and figure out what value project was trying to access. I don't have any more issues to report.

AlanWong-MS commented 6 years ago

@nla-brandonjames ah, I reread what you wrote and I see what you did. Okay, thanks for the feedback! This will help us determine the scope of our issues.

AlanWong-MS commented 6 years ago

@rendmath , @black78 Does the registry path workaround help?

layos commented 6 years ago

My five cents to discussion. We had the same issue in a shared project on TFS. A colleague of mine got this error but I didn't. The difference between us is that he has Visual Studio installed in italian. I don't now if it matters. But it is just an additional info.

RayCon-LP commented 6 years ago

I've update a WebAPI project with OData from VS2013 to VS2017, installed the OData Connected Services and encountered the same issue. Tried installing VS2017 on a newly built machine and had the same problem. As mentioned by @nla-brandonjames the WCF Data Services registry settings are missing along with the installation files.

Had a look at a VM with VS2015 and the files and registry entries are intact.

After installing VS2015 on the project machine, I could generate the reference file. Remove VS2015 and the registry and installation files were removed and back to the issue.

I'm not sure where VS2017 puts the WCF files, as that option was checked in the installation.

@AlanWong-MS, you should try having an installation of VS2017 only and a WebAPI project with OData and try adding the connected service.

mohsenno1 commented 6 years ago

I have the same problem. Visual Studio 2017 Community 15.2.

I tried to debug it using another instance of visual studio. I got this error:

Could not load file or assembly 'Microsoft.VisualStudio.ConnectedServices.Package2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

And, Right after it I got:

"Value cannot be null.\r\nParameter name: path1"

@nla-brandonjames Can you please explain how did you solve the problem in your case? How did you hard-coded InstallLocation into the code? Did you compile the source by yourself? I

mohsenno1 commented 6 years ago

I found a temporary solution: Go to registry: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services]

I my case I found VS 2010 Tooling key. I made a duplicate of that key and renamed it to VS 2014 Tooling.

Now it's working fine.

But this problem can be solved easily by changing the source code:

In V3CodeGenDescriptor.cs#L32 just needs to be checked that if string.IsNullOrEmpty(wcfDSInstallLocation) and if it is then jump to the else statement.

And this will fix the bug.

AlanWong-MS commented 6 years ago

@mohsenno1 can you please open a PR with your proposed fix?

AlanWong-MS commented 6 years ago

Summarizing issue for bookkeeping:

As others have been seeing, the exact method that takes a look at the registry is GetWCFDSInstallLocation() inside ODataConnectedService\src\Common\CodeGeneratorUtils.cs. This method is called only at ODataConnectedService\src\CodeGeneration\V3CodeGenDescriptor.cs inside the AddNugetPackages() method:

var wcfDSInstallLocation = CodeGeneratorUtils.GetWCFDSInstallLocation();
var packageSource = Path.Combine(wcfDSInstallLocation, @"bin\NuGet");

Path.Combine throws the aforementioned exception if either of the parameters is null and PR #68 addresses this issue.

xuzhg commented 6 years ago

Merged related PR at: 196d8b8

xuzhg commented 6 years ago

Please let us know or re-open this if you have further questions.

LiQuick commented 6 years ago

Just installed the OData Connected Service extension via Visual Studio --> Tools --> Extensions and Updates, but still have this issue. Is this already packaged and rolled out? odata connected services 1 odata connected services 2 odata connected services 3

AlanWong-MS commented 6 years ago

There hasn't been a new package yet. I'll be working on the next release. It should be within a couple of weeks.

siberianguy commented 6 years ago

@AlanWong-MS Is it possible to include the fix to this very critical problem?

LiQuick commented 6 years ago

Is there a novice workaround to this? It seems it needs a registry key that is missing on our installations. Can anybody point out which key and if the value must be a meaningful value (path to an executable) or that the value could also be an empty string? I have no right to ask for any action on your part but waiting a couple of weeks ain't an option for me and the other option is reinstalling my visual studio 2013 setup.

mohsenno1 commented 6 years ago

@LiQuick I have mentioned to a workaround in my previous comments.

First install Microsoft WCF Toolkit from the link bellow:

WCF Toolkit

and then go to the registery, find the following key:

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services]

and rename "VS 2010 Tooling" to "VS 2014 Tooling"

It's better to create a duplicate of that key and then rename the duplicate instead of changing the original one.

LiQuick commented 6 years ago

Thank you Mohsenno1 for the help. I got it to work but instead of having "VS 2010 Tooling" I had a "reg folder" with the name "5.6". I exported this folder and changed 5.6 into "VS 2014 Tooling" and it worked (I guess).

AlanWong-MS commented 6 years ago

@siberianguy, we'd love to review and accept any PRs that address that feature gap, but at this time, we don't have resources allocated to the item.

v-tbert commented 6 years ago

I encountered this issue to and @mohsenno1's workaround didn't produce the desired registry key. I had to do the same as @LiQuick. Everyone with a clean install of VS who tries to use an ODATA service is going to get this so I really think it should be prioritized higher but in the meantime, saving the below to a .reg file and importing should work for most people:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services]

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services\VS 2014 Tooling] "Version"="5.6.61587.0" "InstallLocation"="C:\Program Files (x86)\Microsoft WCF Data Services\5.6\"

ghost commented 6 years ago

@mohsenno1 , thank you for the fix, this saved me today! This is indeed a problem that should be fixed asap!

rogerfar commented 6 years ago

@AlanWong-MS You remove a feature from VS2017 and then ship it's replacement broken, I would assume this is top priority at MS, I see VS updates come out every other week and this is still broken.

VeryCrazyDog commented 6 years ago

My colleague encountered the same issue on VS 2017. @mohsenno1 and @LiQuick mentioned a workaround but that will result using an old version of WCF Data Services Tool.

It seems that the required WCF Data Services Tool (VS 2014 Tooling) comes together with VS 2015. My PC and my another colleague PC only installed VS Pro 2015 and never installed VS 2017, and we both have the folder C:\Program Files (x86)\Microsoft WCF Data Services\5.6.4 and according to the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft WCF Data Services\5.6.4, it is version 5.6.62175.4. We also have the registry HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft WCF Data Services\VS 2014 Tooling.

So what I do is, I send the files and registry to my colleagues who have the issue and had VS 2015 uninstalled, and the problem is solved.

AmirImam commented 6 years ago

Hi, Now I have same issue I am using ASP API 2 with OData v3 and Visual Studio 2017 Community How can I fix it

FabianBigler commented 6 years ago

I'm having the same issue with OData V3 and using VS2017, getting the following error: "The specified OData API cannot be updated because OData APIs are now only supported with Connected Services."

The only workaround that works for me is Opening VS2015 to Add or Update OData Service References.

Please fix this!

AdReTos commented 6 years ago

Good day to everyone.

Buy a new computer, and install Visual Studio 2017 Community, wanting to use the connected services, I found the same problem, in an old computer I have VS2015 and VS2017, and it works well, the temporary solution is to copy the folder WCF Data Services that it is found in Program Files (x86) to the computer that has the problem. And add the right keys to the registry and with that everything works perfectly.

I share the folder with everything you need, for people who do not have such material, as try to find the installer of the version 5.6.4 RTM and I was impossible to get, apparently installed with VS2015. https://1drv.ms/f/s!Aj5NbD2-p-qXiBbNUimu7gylWHBW

Greetings from Mexico

LiQuick commented 6 years ago

The whole new connected service tool is flawed. Connecting to a password protected odata service is also not possible.

karpediemnow commented 5 years ago

@LiQuick I have mentioned to a workaround in my previous comments.

First install Microsoft WCF Toolkit from the link bellow:

WCF Toolkit

and then go to the registery, find the following key:

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services]

and rename "VS 2010 Tooling" to "VS 2014 Tooling"

It's better to create a duplicate of that key and then rename the duplicate instead of changing the original one.

After that I was unable to find the key [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services\VS 2014 Tooling] or [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services\VS 2010 Tooling] but only
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services\5.6]

If you are in this situation you need to create it. I have attached the reg key to fix it WCF_FIX.reg.txt

I hope can help somebody!