Problem creating site using Microsoft Visual Web Developer Express 2008 - c#

this is a very newbie question, sorry!
I need to create an aspx website based con C# and am calling some webservices based on some DLL's I already have. Beforem purchasing Visual Studio, I decided to try Microsoft Visual Web Developer Express (is this ok?) creating a Web Application ASP.NET based on Visual C#.
I created the form to enter the data which is submitted when clicking the process button. At this point I need to call stuff from the DLL, which I have added in the Solution Explorer via Add Reference, selecting the DLL from the COM list. But whenever I run the project, I always get the error "the type or namespace xxx cannot be found - maybe a using directive or assembler directive is missing" when trying to create the object.
What is my stupid mistake?
Thanks!

If you look at the error message, there is another half that you havent covered. At the top of each code file that you want to use the namespace from your DLL, you need to include a "using directive" to let the compiler know that it may be linking to that DLL during compilation. Basically the compiler is wondering where something is, and even thoguh you included it in the function, you didnt take the final step of adding in the using statement at the top of the file.

Related

Browser detection in C# (.Net)

I'm in C# land today. I'm trying to write a function which accepts a user agent string and returns an object that gives me at least the browser name and version. So I tried this answer, but apparently I don't have access to HttpBrowserCapabilities. It tells me the type or namespace name could not be found (yes, even if I add using System.Web, it still doesn't show up, or when I type using System.Web. it doesn't pop up, so it's obviously not there).
I'm using .net 3.5, but the documentation for that class shows it existed even in 3.5, so I'm not sure what's going on. I have access to the browscap files - ini or xml. Am I going to have to write this from scratch?
Edit: I've fixed the reference problem. But Chrome is being reported as AppleMAC-Safari 5.0. I'm wondering if I'm going to need a completely different approach. PHP figures it out with the same ini file fine.
Adding a using block does not automatically import the DLL. All a using does is allow you to not write:
System.Web.HttpClient //Or whatever
All over the place, and use HttpClient instead.
You need to add a reference to System.Web to the project before any of its classes will be available to you.
Did you have a using System.Web; statement in your source file?
Here's a tip: if you're using Visual Studio, and you have a reference to the System.Web.dll in your project, if you type the name of a type and press Ctrl-. it will give you a popup menu to add the namespace reference to your source file.
Do you see it in the ObjectBrowser (assuming you are using Visual Studio)? I found the namespace this morning (granted I'm on 4.5 - but documentation shows it has been around since 3.5 and earlier)

VS2008 how do I find the exact location of a class definition (from metadata)

I am using VS2008 and an AddIn to create a web service.
The tool also creates code to access remote procedures (in fact this is another web service).
In the created code some classes are used which will contain the response. So it is a very nice solution.
Now to my problem: When I use 'Goto definition' function, it shows me the class 'extracted from metadata'. So I guess it compiled the class into some library.
Now I would like to know the DLL where the class is defined.
How can this be achieved? To be honest, I manually checked the DLL and either I am getting old or there is some magic in how VS locates classes.
Could someone please give me a kick/hint in the right direction?
Thanks
Ok. I found out myself. It is too easy:
First, I hover the cursor over the tab header and it gives me the location of the DLL. Although this DLL is not part of the project, within the .svc file, the class is known as the declaring DLL is in the bin folder of the web service project.
I find this very strange as I thought that only files being part of the project (i.e. included) or libaries in the GAC are used for name resolving.
Anyway, I learned something new today, which is not part as all.

"microsoft.visualbasic.fileio does not exist" trying to use TextFieldParser

I've seen the above question asked many times on many sites, but I haven't seen an answer that fixed the problem.
The scenario is this...
I am on .NET Framework 4.0, building a C# web application in VisualStudio 2012 Express with the Razor view engine.
I'm trying to use Microsoft.VisualBasic.FileIO.TextFieldParser in my code. From what I've read it is appropriate to do so by adding a project reference to Microsoft.VisualBasic, which I've done, and coding #using Microsoft.VisualBasic; in my view. However when I code...
Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(xxxxxxxx));
...in the view and rebuild the solution it returns errors: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
I know the reference is in the correct project because when I add and remove it I see it come and go from the references folder. I know the code I'm trying to reference exists because I can see it in Object Browser. I've even tried adding the reference using Object Browser instead of through the menus and although it gets added, the results are the same.
The solution it's in is a bit complicated so I tried just creating a test stand alone C# project and I get the same results. I also tried creating a test stand alone Visual Basic project, and sure enough, it works there as advertised. I'm by no means an expert on Visual Studio so I'm guessing that it's just something I'm missing in the configuration, but I'm at a loss to figure it out.
I've spent days on this, so any help anyone could offer would be greatly appreciated.
Right-click on your project and select Add Reference...
In the Reference Manager, expand Assemblies and select Framework. Then check the box for Microsoft.VisualBasic and click OK.
Credit goes to:
https://stackoverflow.com/a/17146200/2530360
I just had the same problem and your question title was more verbose so I figured it should have the answer inside.

Microsoft.Exchange.WebServices is not working in VS2010

I'n using EWS ExchangeService to read emails from outlook... I've coded the in Console project and in VS2008... Everything works fine as it is.. I can read the emails.
To become more familair with VS2010 I created a console project and copied the copied to VS2010 project.
so I added the referene "Microsoft.Exchange.WebServices" (Version 14.2.51.0) in Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll folder.
Everything works as it is, so I see the intellisence, I see the methods properties of Exhange assembly etc...
using Microsoft.Exchange.WebServices.Data;
1st Question:
The issue:
- As soon as I click on the build button in VS2010... I get this error:
The type or namespace name 'Exchange' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) Form here all the methods/properties of Exchange assembly get squeezed underline... Intellisence is not working for Exchange assembly anymore. When I remove the assembly from reference and re-added I get the intellesence back again for Exchange assembly... but it happens again when I click on build :(
so I goto my code and type "Microsoft." I don't see the Exchange word anymore....
So I don't understand why this occurs, it works on VS2008 and in VS2010 it's not working? The only way I think is VS was Framework 3.5 and VS2010 is V4.0
any idea where to look? and how to solve this problem?
2nd question:
I need to get attachments of the email.. so when email arrives on special email account, I need to get the attachment and save the attachment-file to a specific folder. What's the best approach here? Create the code in Console project and create Windows service project? or just Console project or just Classlibrry project and add to Task Scheduler? So I need some advice on this how to approach at project level... The programming logic is already there working.
But as I said in my first question I got it working in VS2008 but VS2010 doesn't know th Exchange assembly after I press the Build button.
Answer to Question 1: You need to switch the target framework in your project from ".NET Framework 4 Client Profile" to just:".NET Framework 4".

Type 'xxx' is not defined, BC30002 error

It is possible to create an instance of a C# class within a aspx.vb codebehind file?
When I try this within the Page_Load event:
Dim oFlow As New Flow(HttpContext.Current.Request)
I get the Type 'Flow' is not defined. The Flow class itself is located here:
App_Code/CSCode/Cust/Frm/Flow.cs
There's no namespace associated with this class.
Any suggestions would be greatly appreciated.
cheers,
devin
There seems to be a few articles on google which say that it is possible to call a C# class from VB directly using a reference. However I have never used this method before. Here is what I would suggest:
Create a new project inside of your solution
Create this project as a c# class library
Compile that project either in debug or release (this will create a .dll in the projects debug/bin or release/bin folder).
Go back to your ASP.Net VB project and make a reference (right click the project in the explorer and your should see the reference option) to the DLL you just created.
Now you can call the c# code just as you would any other class library from your VB code. Also, if you need to make changes to the C# code all you have to do is make them, compile again, and since it is referenced in your VB project everything will be updated auto-magically.
Hope this helps.
Thanks for the response.
The reason why I was having issues is because I'm using IIS 6 on my windows xp box along with the XP PRO IIS Admin Tool and I didn't have the correct site running.
Once I switched over to the proper site within the XP PRO IIS Admin Tool and then recompiled, I was able to call my C# class from within the .vb page without a hitch and intellisense recoginized the class as well :)
cheers,
devin

Categories