Problems converting VB.NET to C# - c#

I am trying to convert some vb.net to C#, but I keep getting errors. At the moment, I am getting the following error:
The name 'Strings' does not exist in the current context
The problem line is:
strUser = Strings.LCase(Strings.Trim(strUserInitials[strUserInitials.GetUpperBound(0)])).ToString();
Anyone know why this is happening?
I have the following namespaces set:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
I am working on a webservice (asmx file).

The Strings utility class is in the Microsoft.VisualBasic namespace.
You can add a reference to the library and use it from your C# code, or rewrite the calls:
strUser = strUserInitials[strUserInitials.GetUpperBound(0)].ToString().Trim().ToLower();

In c# there is no Strings class in System namespace. and in the string change LCase to ToLower, So:
strUser = string.ToLower(string.Trim(strUserInitials[strUserInitials.GetUpperBound(0)]));

Related

Assimp.Net GetTextureCoords missing from Assimp.Mesh

I'm facing a very strange error in my VS2010 project that uses c# + OpenTK + Assimp.net (The packages of the last 2 are from NuGet, so I suppose them updated to their latest version)
When I try to iterate the vector3 of the UV coordinates using:
model.Meshes[n].GetTextureCoords(0)[i]
I get the following error:
error CS1061: 'Assimp.Mesh' does not contain a definition for
'GetTextureCoords' and no extension method 'GetTextureCoords'
accepting a first argument of type 'Assimp.Mesh' could be found (are
you missing a using directive or an assembly reference?)
I don't understand why! Can someone please help me?
AssimpNet is correctly referenced (I'm able to load and visualize any 3D model correctly if I comment the UV part)
And in the using part:
using System;
using System.Collections.Generic;
using System.IO; //Required by Assimp-net
using System.Reflection; //Required by Assimp-net
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using Assimp; //Required by Assimp-net
using Assimp.Configs; //Required by Assimp-net
EDIT: I also tried to change the order of the "using"s... or to remove some of them to see if there was some sort of namespace clashing but without any success
It's simply Mesh.TextureCoordinateChannels[0][i]. GetTextureCoords() does not exist. If you saw it anywhere in a tutorial, let me know where.

Creating Device in C# (Device not recognized as keyword)

I decided to try working with C# over c++ but ran into a problem.
The following code snippet shows the problem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Device;
namespace Project_AREA
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
}
}
}
That's as much code as I have right now.
In private Device device;, the keyword Device is not getting recognized although all the libraries have been referenced and the using directives are included.
Any ideas?
Managed to Solve the problem.. for your reference and also if other run in to the same problem. You must add all the following references to the project: (note all files can be found on your had disk at c:\Windows\Microsoft.NET\DirectX for Managed Code) 1: Microsoft.DirectX.dll from folder 1.0.2902.0 2: Microsoft.DirectX.Direct3D.dll from folder 1.0.2902.0 3: MicrosoftMicrosoft.DirectX.Direct3DX.dll from folder 1.0.2911.0 Thanks for the help tho guys :)

Error while trying use project's classes into another project

i have this structure:
Entity:(It's a Project named "Entity" - type: ClassLib)
Class 1;
Class 2;
Class 3;
DataBase:(It's a Project named "DataBase" - Type: ClassLib)
Class 1;
Class 2;
Class 3;
MainProject: (Windows Form)
Some Forms;
Then what I did was:
Added both projects into MainProject's references
Wrote on the codebehind:
using DataBase;
Worked perfect... But when I try to add the DataBase Project into the codebehind, it doesn't show up while I'm typing and also give me this error:
Error 2 The type or namespace name 'DataBase' could not be found (are you missing a using directive or an assembly reference?)
Ps: All the Classes of the projects (Class 1,2,3...) have the same namespaces wich is the project's name.
I tried some stuff I found on the internet, but nothing worked... Any Idea why?
UPDATE
My Code:
MainProject
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Entity; ( WORKED ! I can acess Entity's Class)
using DataBase; <---------------------------------- (ERROR HERE)

Not able To find A Class in A namespace In c#

I am extracting images from pdf in c#.
Someone has suggested that use Aspose namespace which is a third party namespace.
I have downloaded the aspose and included in my project as a reference.But the problem is i am not able to find the class PdfExtractor which is used to extract images.
I am sharing the link in which some one has suggested to use aspose and also sharing my code.
This is a link
and my code in which i just include aspose
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aspose;
using Aspose.Pdf;
using Aspose.Pdf.Devices;
using Aspose.Pdf.DOM;
using Aspose.Pdf.Generator;
using Aspose.Pdf.InteractiveFeatures;
using Aspose.Pdf.Structure;
using Aspose.Pdf.Text;
namespace Imageget
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
And The class which is suggested in the link is PdfExtractor i am also sharing its code below so one can not waste his time to go to link.
PdfExtractor objExtractor = new PdfExtractor();
//bind input pdf file
objExtractor.BindPdf("input.pdf");
//extract image with specific mode
objExtractor.ExtractImage(ExtractImageMode.Default);
//check if images extracted and save them one by one
while (objExtractor.HasNextImage()) {
objExtractor.GetNextImage(DateTime.Now.Ticks.ToString() + ".jpg");
}
A first sight at google told me that you might need to add namespace:
Aspose.Pdf.Facades
Check out here and see the tree at the left.
and don;t forget to look at my comment at the top, it always help to find the namespace of class if i am unable to find it.
hope it helps!

Cant type System.IO.Ports shorthand

I have the following code but still have to type full path to use the System.IO.Ports namespace even though I have the using clause in place. Am I missing something in my reference list?
The = new SerialPort returns a Error 5 'SerialPort' is a 'namespace' but is used like a 'type'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SerialPort
{
public partial class Form1 : Form
{
System.IO.Ports.SerialPort counter = new SerialPort("COM5");
public Form1()
{
InitializeComponent();
}
Thanks
You're declaring a namespace of SerialPort. Don't do that. That's what's causing the problem.
All you've got to do is change the namespace, and you'll be fine. You could use an alias as per Honza's request, but I think the code would be clearer to everyone if you just renamed the namespace.
It's because your namespace carries the same name. Either rename your namespace or use an alias for the serial port, like this:
using SP = System.IO.Ports.SerialPort
And then you can use
SP counter = new SP("COM5");
But as Jon suggested, renaming your namespace is a clearer solution to anyone who'll read your code.

Categories