How to use System.Xml.Linq in Unity C# Script? - c#

working with unity and c# and when I try these line
using System.Xml.Linq;
I get this error
The type or namespace name Linq' does not exist in the namespace
System.Xml'. Are you missing an assembly reference?
So I found online, through a lot of searching, that Linq can cause problems, and you need to manually add a reference in MonoDevelop. So I added a reference there (by right clicking References in the solutions pane, clicking Edit References and browsing for System.Xml.Linq)
Still no luck,
Any ideas?

I think this SO post will answer your question...
https://stackoverflow.com/a/875704/1246574
It's pretty much the same issue you're having.

You can't modify the monodevelop (or visual studio) solution or project manually. Because they are generated by Unity. Even if you modify it, Unity can overwrite your changes when it regenerates the solution files.
The reason you can't use some namespaces is the .net/mono version selected in your Unity project settings.
Search for "API Compatibility Level" in this documantation http://docs.unity3d.com/Documentation/Manual/class-PlayerSettings.html
C'mon people, Stop modifying the generated code files. This is 2013!

from this post, I found that Unity doesn't support .NET 3.5 by default (which is required to use Linq). In the settings Xtro talked about, you can only choose .NET 2.0. Instead, you need to drag the desired .dll file into Unity like a texture. Kinda hackish, but it works. Once again, like Xtro said, there is NO REASON to edit the MonoDevelop settings. They have no affect on the final compilation.
EDIT: See Xtro's answer for an alternate solution. He was able to make Linq work by changing the API Compatibility Level to .NET 2.0 (not Subset).
EDIT 2: I just updated from Unity 4.1 to 4.2 today and got an error that Linq was defined twice. by deleting the .dll, I solved the error. Note I'm still using .NET 2.0 Subset. Looks like they added Linq support by default.

Related

Reference seemingly not working, no apparent error thrown

I have superficial knowledge on referencing libraries in projects. Usually most of the time a simple 'add reference' and then browsing to the appropriate path, just works. I am following an issue I will try to explain , and show all the approaches I tried to tackle it.
I am trying to use AutoIt. In their website it is stated that simply adding the .dll and using it, is enough to integrate their functionality in visual studio.
I am doing just that but for the moment I can not get my head around what is happening.
AutoItX is a public static class, as also the Run function is the same (public static). After adding the reference I can navigate to the appropriate .cs (if I control click on it for example). So the class AutoItX is not something unknown for the project. Moreover, the function Run indeed exists
however not inside the project itself. AutoItX also needs staff from (dont know if it is important):
The main error is that AutoItX doesnt exist in this context.
I have tried to register the dll, I have tried to add the com reference and remove it, I have tried to move the .cs files inside the project. None of those corrected the issue.
Any help would be valuable. If I missed something and you need extra info, I am willing to provide it. (Latest vs, latest autoit version, .net framework type of project).
Actually the above works.
For future reference.
The reason I did not try it first was, that they propose in their website to reference the autoItX.assembly.dll. This is probably deprecated and does NOT work anymore.
Second, if you have already referenced it , downloading this from NuGet WONT fix it.
Finally, the NuGet package does NOT work with .net CORE but ONLY with .net Framework project
I installed AutoItX.Dotnet 3.3.14.5, my test is no problem.
You can refer to my steps to create a new project to test it.
Right click References=>Manage NuGet Packages=>Browse=>AutoItX.Dotnet=>Install
Running result:

Really Confusing Reference Situation for System.IO and System.Runtime

First of all, thanks for the help in advance, and excuse me for my relative lack of knowledge on these subjects, and this long post. I have a strange reference issue I'm trying to work out. I've done many hours of research on this subject, but I think my limited knowledge is holding me back from understanding. I'm losing my mind a bit here.
We are reviewing a project and came across an odd situation where there are references to System.IO and System.Runtime in the original .csproj file for an application (Sitefinity 10.1.6502), but in the copy of the .csproj we have on file post-development they have been removed. There are still references to System.Runtime.Caching and System.Runtime.Serialization in both.
When I looked online and in Sitefinity's public Git example repos, I found that about 1/2 of the examples with code for the same version DO have and like the original file does, and 1/2 DO NOT have them like the file in our repo. Some appear to have those references added at a later time when upgraded versions (to 10.2 or 11).
I also do not see System.Runtime.dll in the current /bin folder, or see it mentioned in web.config. I do not have access to the GAC.
The question is whether these missing references will cause any problems. The project seems to compile properly in VS2017 using the post-development .csproj file we have (without System.IO and System.Runtime)
We believe the project was originally built in VS2015, and found this article that mentions the exact references we're dealing with, so perhaps VS2015 was part of the problem? Unresolved Project References for System.IO, System.Runtime
I understand these are facades and that System.IO is a namespace in System, which is directly references in both .csproj versions, so that should be covered, correct?
The real question is whether the missing in the post-dev .csproj file could cause any issues. Like I mentioned above, the project is compiling without it in VS2017, and the files seem to work fine on a testing server (can navigate the front-end web pages and all functionality works, but we have not been able to test any of the back-end functionality due to it sharing a database with the live environment (out of our control).
Through my research I've seen it mentioned that System.Runtime should get automatically included during tooling/compiling, and that in normal circumstances it does not need to be directly referenced like it is in half the repos we saw. Is this correct?
I worry less about System.IO because it is already included via System, but from what I understand that isn't the case with System.Runtime
Again, thanks so much for helping clear this up for us, we're beginning to go batty trying to figure out if this is an issue we should worry about or not!

C# - Gtk.ComboBox Does Not Contain a Definition for 'NewText'

I'm writing a C# Gtk# application under Mono/MonoDevelop in Linux Mint 17. I have a ComboBox on a form with 3 items in it. I was able to place it and such fine however, I get an error in the designer code stating that the ComboBox doesn't contain a definition for 'NewText'. The Mono documentation at docs.go-mono.com says that this NewText method is how you add items, however, apparently mine doesn't have it.
My MonoDevelop version is 4.0.12
The projects target Gtk# version is 3.0
I have the following references and their versions referenced in the project
And finally, the designer code
//top of file declaration
private global::Gtk.ComboBox framestyle_Val;
//further down, this defines all the items
this.framestyle_Val = global::Gtk.ComboBox.NewText ();
this.framestyle_Val.AppendText (global::Mono.Unix.Catalog.GetString ("Single Sprite"));
this.framestyle_Val.AppendText (global::Mono.Unix.Catalog.GetString ("Left/Right Sprites"));
this.framestyle_Val.AppendText (global::Mono.Unix.Catalog.GetString ("Left/Right/Upside-Down Sprites"));
It's worth noting that apparently there's no AppendText definition/method either but I assume that'll be straightened out once we get this one straightened out.
Any ideas? I'm confused myself. Thanks in advanced,
Mike
I had the same problem. MonoDevelop seems to be unable to generate proper code to use with Gtk#3.
You may want to install Gtk#2, this will not override the GTK#3 installation, and target your project with this version to be able to use MonoDevelop's visual design abilities.
And maybe you will need to create the clean GTK#2 project once again.
If you have found a solution to use GTK3, please give me an idea.

Can't find `DataProtectionScope` and `ProtectedData` classes in System.Security.Cryptography

I've referred the file System.Security.dll as described in this article but according to my IDE, the line using System.Security.Cryptography; can be safely removed as it's not being used.
The same IDE tells me that I've got an error with DataProtectionScope and ProtectedData. Those are supposed to be in that namespace. However, when I dot my way through the packages, I can't see them in there.
Is the article wrong? How can I access the two classes?
As #Coral Doe mentioned in a comment under #Dave Lucre:
"Had a similar problem and this worked. using System.Security.Cryptography; didn't [show] me [ProtectedData] and ProtectedMemory until I had referenced the System.Security.dll for the specific framework."
This fixed the issue for me. Specifically, I performed these steps:
Open the project in Visual Studio.
Right-click the project's name in Solution Explorer then choose Properties.
Click the References tab on the left.
Click the Add button.
Click the .NET tab.
Select System.Security and click OK to add the reference.
Hope this helps.
I have referenced the System.Security.dll here: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Security.dll
Added using System.Security.Cryptography; and I can see both DataProtectionScope and ProtectedData.
I'm targeting the .net 4.0 full framework (not client profile).
What framework are you targeting?
I had to add this NuGet package in addition to System.Security.Cryptography.
It is https://www.nuget.org/packages/System.Security.Cryptography.ProtectedData/.
After that, System.Security.Cryptography became "used".
As #Dave Lucre asked, what framework is your application targeting? Visual Studio creates all new applications to use the Client Profile by default (which is asinine in my opinion), and it causes all sorts of trouble if you don't specifically change it back. Give that a look, then see where we go from there.
Remove references System.Security.Cryptography and add it again.
It works in my case.
I'm sorry, I know that this is a quite old post, but I'm having this issue now and the only workaround that I've found is:
Follow the steps mentioned in George Brian's answer
Use System.Security.Cryptography.DataProtectionScope scope = System.Security.Cryptography.DataProtectionScope.LocalMachine; instead of DataProtectionScope scope = DataProtectionScope.LocalMachine;
This might be a slap in your face because you've probably tried that (and you haven't, you might deserve one). What happens if you reinstall the whole IDE? And I meant really the whole thing. Remove the framwork, the VS, remove the files, go paranoid and clean up the trash can, switch to a different installation directory etc. Does the problem still remains?
I know it doesn't explain why it happened but at this stage I'm guessing you're mostly interested in how to kill the problem.
If you have access to a spare computer - why don't you install VS on that machine and see if you can reproduce the error. If not, then there's something fishy with your primary machine and you'll probably never know what happened.
I'm stressing here that it's only a list of general suggestions that every programmer should rely on when nothing sane nor logical seems to work. And yes, I do hate computers. I love programming but I hate computers. They are like small, evil people with keyboards...

C# Class Library method summaries not showing in intellisense of vb.net project

(VS 2008)
I'm using a C# library for my VB.NET project. And the method summary/notes or what they are called do not show in intellisense. Is this supposed to be like that? Or is there something I must do to fix it? And if not, will VS 2010 be able to do this?
EDIT: Still unresolved. Now building library dll + xml file, but how to import the xml file in my vb project?
See image: http://i52.tinypic.com/25kh5xw.png
In C# library, go to the properties on the build tab, and check the checkbox for including XML documentation and specify the name and path. After that include the new library in your VB.Net project.
one reason could be resolved by importing the namespace needed
another reason could be due to faulty writing
if you send the code where the problem is we might be able to help you
If you're using source control (TFS or Github) then you need to the following:
Check in ( Push) for safe return point (base line)
Delete the references from the project.
Delete the custom dll's from the solution.
At this point the libs are marked as [removed], if you would add them again at this point, they will just be marked as [changed] again. This did not include the summaries for me.
Check in (push). dll's are now removed from source control as well.
Drag and drop the dll's (including xml) into the solution (I recommend using this method for including dll's
Add references to these dll's via Browse.
Check if you have summaries.
Check in (push).

Categories

Resources