Using System.Web in Xamarin android (xamarin.android.dll) - c#

I am pretty new to android development and using Xamarin for now.
All looks nice, however as soon I try to use HttpUtility.UrlEncode or HttpWebRequest I need the System.Web.
If I add the System.Web to the references its not being accepted.
Some research gives me the idea that xamarin.android.dll should have the System.Web.dll however I have no idea where to find this one.
Does anybody know how to solve this so HttpUtility and HttpWebRequest will be available in my android project?
Any help would be very appreciated!

HttpWebRequest is part of the System.Net assembly while HttpUtility is part of the System.Web.Services assembly.
(Xamarin Studio).
To add those to your project, simply right click the References folder and choose Edit references
In the Edit references dialog you simply make sure the checkbox is checked for System.Net and System.Web.Services.
(Visual Studio)
Right click the References folder and choose Add reference. Next scroll down the list in the Assemblies -> Framework tab and make sure the checkbox is checked for System.Net and System.Web.Services.

HttpWebRequest is included in the System.Net namespace (System dll), and HttpUtility is in the System.Web namespace (requires System.Web.Services dll).
For a reference of which namespaces are available, and which dll they live in, see Assemblies.

Uri.EscapeDataString or Uri.UnescapeDataString may also be an option.

Related

Cannot find ConfigurationManager in class library

So, I have a class library that I know will be used by websites and I need to access the config settings. I added a reference to System.Configuration, but I cannot find ConfigurationManager in the class library. A couple of things, one when I added a reference to the System.Configuration, it shows up as "System.configuration" with a lower case 'c', which I thought was odd. Another thing, when I access System.Configuration, the closest thing to ConfigurationManager is "ConfigurationSettings". I viewed the properties of the reference in a web app that allows me to use ConfigurationManager and this class library and they both point to the exact same file. Do I need to do this another way?
Here is a SS of my reference to it:
See https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager%28v=vs.100%29.aspx
It lies in System.Configuration namespace and assembly System.Configuration. Make sure you go to Framework tab in Add references and select System.Configuration
As of Visual Studio Community 2017, I was not able to find the DLL using any of the methods that are listed here in this answer nor in any of the more antiquated responses on this site or others.
I had to find this NuGet package, which was a little nerve-wracking for me as I've never used NuGet, and then installed it using NuGet which is shipped with Visual studio.
You can install version 4.4.1 via the command line using:
Install-Package System.Configuration.ConfigurationManager -Version 4.4.1
Or, by searching for "System.Configuration.ConfigurationManager" in the Nuget Package Manager.
For me, I was getting this even with the reference added. I tried shutting everything down and re-opening the project and still it wouldn't resolve what I had typed in.
Finally I just deleted my lines of code and typed in the fully qualified "System.Configuration.ConfigurationManager.AppSettings", and it "found itself". No real explanation for why that worked. It even figured out that the "using" reference at the top of the code was there so I didn't need to qualify it any longer. Weird!
I think it just comes down to some quirkiness in VS when doing some references. No real explanation to it.

The type or namespace name 'Device' does not exist in the namespace 'System'

I am trying to work with GeoCoordinate which is meant to be supported by .Net Framework 4.5. I am working on winodws 8 and I have .Net Framework 4.5, but I keep getting The type or namespace name 'Device' does not exist in the namespace 'System' error.
Any solution?
The type or namespace name 'XXX' could not be found...
Always bear in mind, if you get this error there are three possibilities.
You missed the using directive.
You missed the Assembly reference
You have "using directive" as well as "Assembly reference" in place but the current project's target framework version is lower than the referenced assembly target framework version.
Almost all the cases above three steps should solve the problem.
Hope this helps.
Does not have added reference of System.Device dll in your project.
Steps to Add Reference.
1. Right click on the Reference folder on your project.
2. Select Add Reference.
3. Expand Assemblies option.
4. Search System.Device in the serach box at right corner side.
5. After searching, click on checkbox to select and click on ok.
If you are using VS.NET:
Right click on the References folder on your project.
Select Add Reference.
Select the .NET tab (or select the Browse button if it is not a .NET Framework assembly).
Double-click the assembly containing the namespace in the error message.
Press the OK button.
If you are using the command line, use the /r: or /reference: option. For Example:
csc.exe /reference:System.Drawing.dll MyFontDisplayApp.cs
When you recompile, this error will no longer appear.
It is also possible that your project uses x64 libraries and your machine has limited x64 libraries. I think this happened in my case.
Possible Solution: I copied library from x86 folder to bin folder of my project. Then added the new reference(discard the old reference to same library). AND IT WORKED.
Note: Please correct me if I am wrong here.

Cannot compile solution?

I have business layer in my solution. I added console project to the solution. Added necessary reference to console application. Created instances of classes in business layer. I'm using resharper so code looks correct.
when I try to build I get the error like
Error 127 The type or namespace name 'BusinessLayer' could not be found (are you missing a using directive or an assembly reference?) C:\ConsoleApplication\Program.cs 13 25
if I reference business layer from web project under the same solution it compiles, but with console it's not.
do you have any idea what can be the problem?
Add using BusinessLayer; in the top of your application, if you already did that, then try to clean and rebuild the solution.
Also make sure that both the library and the console application have the same .net framework version, for example both are 4.0 and not one of them 4.0 client profile...
You seem to confuse a library (project) reference and a using statement judging by your comment:
I have the reference at the top of the page.
You need both to add a reference (right-click your project's References folder in Solution Explorer > Add Reference...) and add a using directive at the top of the code file to import the required namespaces.
You'll have to add a reference to that assembly from your console project.
You add references at the project level not the solution level, so the reference you added to your web application doesn't help your console app.
Right click over your solution, configuration manager, you will see all projects, be sure that you have marked all necessary projects to build with right platform.
Hope it helps.
Rebuild the BusinessLayer class library and build your solution again.

Visual Studio 2010 -- are you missing a using directive or an assembly reference?

When I add a reference to my dll in Visual Studio project, I am able to use it, but when I compile my code or try to run it, I get an are you missing a using directive or an assembly reference?_ Error. I am able to confirm that I have the right using statement for my namespace and I am able to confirm that the dll is correctly loaded.
Anyone have any idea what I may not have right in this?
Go to project settings and make sure that you are not compiling the project for a .net version that includes the text "client profile".
I had just had an issue precisely like this, even if this is an old question thought I would add my 2c on what fixed it as none of the other answers helped:
For whatever reason, when I built the solution top to bottom a certain dll was not getting updated and output that held changed code. So while my solution had no visible errors, when you attempted to build, it was still referencing the old dll and started complaining.
It was simply a case of directly re-building the offending project and after that it picked up the latest dll and built happily.
This seemed to be a freak accident as no configuration had changed between when it worked / when it didn't.
Sometimes, JUST REBUILD THE SOLUTION.
The location of the DLL is important.
If you add a reference on your local machine to a DLL that is outside of your Visual Studio solution, it isn't necessarily copied into your solution files (depends on the type of solution/project).
If this is your problem, then you need to either put the DLL in the same path on the other machine, or copy it into your solution so it gets deployed along with the solution files, and change the reference.
You can also handle this with build instructions, but that might be beyond your aspirations at the moment.
Most likely your dll is referencing another dll that the client project is not referencing and your dll code is exposing a type or an interface from the 3rd dll to the client code.
If you post the exaCt message, we'll be able to help better.
Are you using .net 4.0?
If yes, this dll is probably not compatible with .net 4.0
In my case, the main project (WinForm) was configured Framework Target: FW 4.0 "client profile". I change to FW 4.0 and work perfect!!.
At first time i was looking in the referenced projects and they were ok, but de main project doesn't. I hope this help. Thank you.
In my case this compilation error has gone after adding the reference to Microsoft BCL Build Components via "Manage NuGet packages" context menu on problem project.
Before: I had project Main (console application) referencing project A (class library).
Project A had dependency on Microsoft BCL Build Components.
After: I started refactoring where I picked out several classes to the separate project New. It also depended on A. But the compilation error occurred on project New as if there was no reference New -> A (although Visual Studio didn't highlight allegedly not found interfaces and classes listed in the error list of compilation).
So I checked project A's dependencies and found there Microsoft BCL Build Components.
After adding it to New's dependencies everything worked fine.
The most interesting thing is that Main did not contain this dependency and it didn't need it.
Hope this helps.
You just Have to check your namespace of that class file again...it will work

How do I include System.Windows.Shapes?

I am using Visual Studio 2008 with the .NET Framework (v3.5). I cannot seem to use System.Windows.Shapes, or anything System.Windows.* besides Forms.
Here is the link to the class description:
System.Windows.Shapes (MSDN Library)
Is there some special thing I need to do to use it?
I checked in all of the framework folders, and the only dll/xml files I have for System.Windows is System.Windows.Forms.
What do I need to do to get this to work?
This class is part of WPF, from MSDN:
Shape Class
Assembly: PresentationFramework (in presentationframework.dll)
You need to add a reference to the PresentationFramework library.
In VisualStudio, right click on your project in the "Solution Explorer". Select "Add Reference". The "PresentationFramework" library will be under the ".NET" tab. You may also need to add "PresentationCore" and "WindowsBase".
You can see your project's current library references by going to the "Solution Explorer" and expanding the "References" item.
You may need to add a reference to the library, probably System.Windows.Presentation
Edit: It is in the PresentationFramework library
Add reference to PresentationFramework from .Net tab
write using System.Windows.Shapes
and you are done!
Other solution that works in .Net 4.0:
Go to referenes->add reference and choose PrsentationFramework under .NET tab.

Categories