-2

Clarification

This question is, not a duplicate of the linked suggest as this is a UWP based issue where System.Data.Linq namespace cannot be referenced. This was closed as a duplicate question previously however this is a different problem. This isn't standard .NET, it is the Universal Windows Platform

How does one convert a base64 string to System.Data.Linq.Binary type within UWP.

The issue is occuring when I am attempting to send data over to my WCF service which is using a linq to sql datacontext class. The field in the database is the image type and the class created by the linq to sql datacontext changes the type to System.Data.Linq.Binary rather than byte[] (which is what I was using when it was a manually created class.

So far my attempts have been fruitless. Normally I would send it over as byte[], however if i use Convert.FromBase64String(mystring) I get the error

unable to implicitly convert byte[] to System.Data.Linq.Binary

Clarification

This question is, not a duplicate of the linked suggest as this is a UWP based issue where System.Data.Linq namespace cannot be referenced.

Takarii
  • 1,612
  • 2
  • 18
  • 29
  • 1
    Have you even looked at the documentation? System.Data.Lin.Binary has a single constructor that takes a byte array... https://msdn.microsoft.com/en-us/library/system.data.linq.binary(v=vs.110).aspx – Chris Feb 07 '17 at 14:20
  • 1
    Not a duplicate as that one is a winforms example and has access to a namespace I cant reference in UWP – Takarii Feb 07 '17 at 14:21
  • @Takarii: The accepted answer on that question involves only the class you want (so I presume you have access to) and the byte array you want to convert to that class. Can you explain what namespace you think you need that you can't reference? – Chris Feb 07 '17 at 14:22
  • 1
    @chris the namespace i cant reference is System.Data.Linq. UWP will allow me to reference System.Linq, but that doesnt contain the binary class – Takarii Feb 07 '17 at 14:25
  • 1
    And it won't let you reference `System.Data.Linq`? I'm very surprised that you can write code that requires an object of this type without you being able to reference the place that it is defined... – Chris Feb 07 '17 at 14:27
  • `System.Data.Linq.Binary` isn't a namespace. –  Feb 07 '17 at 14:27
  • The code asking for the System.Data.Linq.Binary type is within my WCF service, which does have access to that class and has assigned it to the variable within the datacontext based on the database field. – Takarii Feb 07 '17 at 14:28
  • Can you not just change to and from the `Binary` class in your service? – Chris Feb 07 '17 at 14:31
  • Why this has been flagged as a duplicate I have no idea, given the referenced question is a different platform to what Im using... – Takarii Feb 07 '17 at 14:47
  • Different platforms can have the same or very similar solutions, can't they? –  Feb 07 '17 at 14:56
  • @Amy yes, but UWP is more closely related to WPF, thus some elements are missing or changed. For example, UWP cannot access an SQL database directly and requires a service layer to provide that functionality. – Takarii Feb 07 '17 at 15:04
  • @Chris Still cant convert, however I modified the types within the WCF service and it appears to allow me to move things. I wasn't sure if I could change the assigned datatypes within the generated datacontext class due to potentially breaking things. – Takarii Feb 07 '17 at 15:05
  • Well, if different platforms can have the same or very similar solutions, then this is a duplicate of the marked question. Being of different platforms is not sufficient to make this not a duplicate. –  Feb 07 '17 at 15:13
  • @Amy The question was not asking the same thing. It was asking how to do it within UWP, not winforms. If the question was "how does an engine work" but was talking about a diesel engine, a question asking the same thing about a petrol engine wouldn't be a duplicate. This is the same situation. – Takarii Feb 07 '17 at 15:18
  • "It was asking how to do it within UWP, not winforms. " That is irrelevent if the same solution works. Sorry, this is a duplicate. –  Feb 07 '17 at 15:34
  • @Amy the same solution DOESN'T work. if it did then I wouldnt have asked the question! – Takarii Feb 07 '17 at 16:08
  • 1
    That's the first time you've said that. Up until now, your only argument has been that the questions are different platforms, despite my repeated insistence that such a difference is irrelevant. Okay then, why doesn't the answer in the dupe question work here? –  Feb 07 '17 at 16:13
  • @Amy litterally explained this in my very first comment. "Not a duplicate as that one is a winforms example and has access to a namespace I cant reference in UWP " – Takarii Feb 07 '17 at 16:45
  • Okay, I give up. Good luck to you. –  Feb 07 '17 at 16:56

1 Answers1

0

Linq.Binary has a constructor that takes a byte[] which is available in UWP pre Windows 10.

So in this case:

var x = new System.Data.Linq.Binary(Convert.FromBase64String(mystring));

For windows 10 or above, you would need to change the object in the Web Service to take a byte array, by changing the Entity type.

Ben Temple-Heald
  • 708
  • 1
  • 6
  • 16