Bypassing member names cannot be the same as their closing type

Similarly :. member names cannot be the same as their enclosing type except I cannot change metadata, I want to just ignore the class completely

I am trying to add a service link in Visual Studio 2010, but I am getting the following error.

Failed to configure custom DataServiceClientGenerator tool. Data Service Client Code Generation Error: The specified schema is not valid. Errors: (0,0): error 0042: the name foo cannot be used in the type Microsoft.Crm.Sdk.Data.Services.foo. Participant names cannot be the same as their closing type.

I understand that this error is caused by someone calling the field foo in the foo object, but I cannot change this.

therefore, not being able to make any changes to CRM, how can I generate a link to a service?

I thought about loading $metadata and then deleted the offending type and then saved it (since the type is not the one that I will use anyway). But I do not know how to make it work, because it is not too straight forward.

I tried to make a link to the service both with C # and VB.NET and didn’t work, ideally there would be a solution that works for both, but at that moment I would be open to a solution that works only for one of them.

+4
source share
2 answers

I decided how to solve this problem.

 http://localhost/myWcfDataService.svc/$metadata 

Save this result to disk, for example c:\metadata.csdl

Then manually edit the file and delete (or rename) the damaging field (this will lead to the fact that it will not be used in your service, but it is better than the whole service does not work).

Then run the following:

 c:\Windows\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /language:CSharp /in:c:\metadata.csdl /out:c:\serviceReference1.cs 

Now add the newly created serviceReference1.cs file to the visual studio project, find the class that inherits from System.Data.Services.Client.DataServiceContext , this is your service entry point.

Further information can be found here .

+6
source

Thanks to Seph, I came up with a slightly improved way to add the actual link, rather than a simple .cs file:

  • Save your http://localhost/myWcfDataService.svc/$metadata as a file, for example. myService.csdl
  • Edit it to resolve names cannot be the same as their enclosing type manually. This is caused when the class has a field with the same name. I decided to rename classes, for example. from foo to foo_ . Instead, you can rename the fields. Run c:\Windows\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /language:CSharp /in:myService.csdl /out:serviceReference1.cs to see when you fixed all the errors.
  • Rename myService.csdl to $metadata
  • Temporarily run some web server in the same folder as $metadata . For example, I installed python 3 and just ran python -m http.server from the folder where $metadata .
  • Add the service link in Visual Studio as usual, but use your temporary web server address. In my case, it was http://localhost:8000 . Visual Studio will request /$metadata and generate everything.
0
source

Source: https://habr.com/ru/post/1413884/


All Articles