Visual studio: Can and cannot access a namespace - asp.net

I'm getting a strange warning when hovering over an OracleConnection object in visual studio. It doesn't seem to stop my website from working fine, but the warning bugs me.
It seems that the class and Oracle.DataAcces.Client namespace is both visible and not visible to my project at the same time.
Here are some pictures:
I have no idea what is causing this; I already have the Oracle.DataAcces reference in my project references. What I suspect that is happening is a bug that would cause my project name to interfere with my namespace, but that doesn't seem to be it.
I tried changing my namespace name and project name to different things, and I still get the same result.
And for some reason the project shows up twice in the navigation bar:

Did you check if the version of the Debugger matched with the version of the Oracle.DataAcces.Client library? That is, for e.g., if you're using x64 bit version Debugger then you should make sure the dll file is also x64. I was having trouble accessing this reference today, and this fixed it. Hope this helps!

Update
After some research, usage of the scientific method and throwing things are rotating blades and seeing what sticks this is what I think might be happening, and I think I found a "solution/workaround" to it.
It appears as Visual Studio is trying to add some temporary DLL/reference to a temporary DLL/project containing all the namespaces that aren't my Web Application's Directory.
Here is what makes me think that this is happening:
When opening the Object Browser Ctrl + Alt + J, There are multiple instances of the projectX Project. Using Dot peek I determined that one of them was the compiled version of my project and the other is some weird project without the main namespace (projectX):
Cleaning the project sometimes work, but the best solution so far has been to go into the solution and files delete the bin and obj folder from my project folder and restart visual studio.
Only using the projectX namespace with no sub-namespaces doesn't fix the problem all. The additional projectX instance in the object browser contains the same thing as the normal one, minus the files and web page objects in my main directory.
So here is my solution:
Create a class library in the solution and put all your classes in it. Then move the references that your class needs to your new class library. Finally, add a project reference to the Web Application pointing to the class library.
It looks like I manage to find a fix but, but I'm going to have to try it for longer to make sure of it.
Follow up
It appears that the solution I found works very well and won't cause the problem to happen again, therefore I recommend it.

Related

Class in App_Code folder not accessible in vb.net website project

At work I have been asked to make some amendments to a vb.net website project i've not worked on before. I've cloned the code from TFS and opened it in VS2019 but there were errors when I tried to run it. I know the website runs because my colleague has been working on it, and it is also live on a server and being used by our clients.
I have fixed some errors in the web.config and added some missing references, but now i'm getting an issue with a class called Translation which is in the App_Code folder. The class is used all around the website but i'm getting the error:
Type 'Translation' is not defined.
All of the solutions i've come across say that I need to change the build action on the class to 'compile', but that isn't possible for a website because there is no build action property. The other suggestion i've seen is to add a 'using' statement but as the class has no namespace this is not an option.
I've seen lots of people asking how to do this for websites but nobody has provided an answer, so i'm hoping someone out there can finally come up with a solution which can help me and anyone else struggling with this problem.
There is often a problem with app_code. In fact two fold. First up, is IIS will compile the code in that folder and NOT Visual Studio. This can lead to problems on deployment (some (a lot) of web sites don't have the newer rosylin complier, and I find some of the great new features (such as free form strings in code) will not compile.
But expand the app code, and then right click (properties) for say the given class, or module code you have, and change/set this: (build action)
Change above "build" action to compile (if it not already).
And even before you do above, try a re-build all (that often fixes this).
So, change above - it possible that the code/module you added to app_code not been (ever) compiled, and thus not seen in your project).
So, I actually now often create my own folder called "MyCode" and often avoid the issues of app_code. However, you might be dealing with a existing applcation.
You could also try doing this:
Rename app_code and add it again:
eg:
but, I would first try setting the code module/or class in app_code to compile in the properties sheet first. And try a re-build all.
In fact, exit VS, re-load, open project. rebuild all. Do that first, just in case (since then you don't make any changes). If exit/reload don't work, then as noted, right click on the module/class in app_code and set build action to compile.
And last but not least, you could try a re-name, and add the app_code folder - since it a specials .net folder, and manually adding that folder often does not work (don't just add folder - add "asp.net" folder) - you need to let VS add it for you as per above screen cap.
After many painful hours i've finally got the code running - mostly thanks to the efforts of my colleagues and my boss. It seems the existing project wouldn't run for me so my boss created a new project and added the required websites to that. After some fiddling with the configuration he got it working.
So unfortunately I cannot provide an answer. Apologies if you've arrived here looking for one. I'm not sure this is actually an issue anyway as I never found anything about anyone else having the problem.
Thanks to Albert D. Kallal for trying to help

How to solve this error? - 'Resource.Layout' does not contain a definition for axml file

Am new to Xamarin and is currently building a very simple app using the tutorial from Youtube. Am just in a middle of the video when I got this error even tho I carefully followed all instructions. And even the instructor in the video was able to run his app successfully
Here's the code where I'm getting the error:
var view = inflater.Inflate(Resource.Layout.SignUp, container, false);
For me it is caused by namespace changes. After I corrected the namespace in project properties, then I can build again
I just deleted my newly created axml file, rebuild, add it again, and this time, clean and rebuild.
Everytime I added a new axml file, I clean and rebuild. That's all, thank you :).
Actually this problem occurs when your ResourceDesigner.cs file has not yet mapped the file that you added to your resource directory.
The easiest way i would suggest to handle this situation is you comment the code you are trying to write and clean build your project and it will work like a charm.
Good luck!
In my Resource.Layout.toolbar, Resource was ambiguous between Android.Resource and Xamarin.Forms.Platform.Android.Resource. Instead the one that works for me is [Project name].Droid.Resource. Clean, deleted bin/debug and now it's fine
Resource.designer.cs was excluded from project. Solved by including back.
In Xamarin.Android this problem can be resolved by saving other axml/xml file. Many times cleaning solution, deleting bins/obj doesn't working for me.
In my case my Main file was configured in the Build Action as AndroidResourceAnalysisConfig and then change property to AndroidResource then Build my project and it works.
I had a lot of "XXX" does not contain "XXX" errors like this after a git reverse operation. Very annoying.
I tried all the solutions I could find, all without luck. Finally I magically fixed it by going to the Android project properties, Android Options, then unchecked "Use Fast Deployment (debug mode only)". I then built the project and it worked. Then I went back and checked that option so it was back to normal, and everything is fine.

Cannot Build Xamarin.Forms From Source Code

I have downloaded the Xamarin.Forms solution from GitHub and I am trying to build the solution. Visual Studio does not build, generating more than 70 errors, as simple as the one below:
"The type or namespace name 'IOnClickListener' could not be found (are
you missing a using directive or an assembly reference?"in
Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs
When I investigate the code, I see that there is really no reference to Android.Views.View in the using statements, so it seems fair.
Am I making a mistake somewhere?
It's not easy to get to the answer without digging into the logs but here are some steps that have helped me in the past.
Android Specific Steps:
Check the logs for any problems that stand out, look at the top most error first and work your way down. Output window -> Show output from Xamarin Diagnostic
If you find unzipping problems you might have to visit the Xamarin folders to delete the zip causing problems and Xamarin will download a new one.
C:\Users{USER}\AppData\Local\Xamarin
If you get loads of Xaml and Resource errors you might have to delete the contents of the file.
Resources\Resource.Designer.cs
After deleting the content(not the file), clean the solution, rebuild the project.
If you still have problems try to either downgrade Xamarin.Forms or upgrade it.
Change Api level to a higher one on the project properties.
Hope one of these helps.

Why does visual studio give me Type is not defined for my App_Code classes?

"Type 'HR.Database' is not defined'
I get that error for several classes that are stored in the App_Code folder in the Error List panel when building my project.
It is a class I wrote with namespace HR
How can I reference it or alter the project to recognize those classes and remove the error?
I thought I should reference it but when trying to add a reference there are no items in the list of projects. Also, they are .vb files and not a .dll
I wasted the better part of a working day on this problem before figuring it out...
When you add files to App_Code, Visual Studio sets the "Build Action" property to "Content", instead of "Compile" which it does for all other classes. So your classes don't get compiled, and then VS complains that it can't find them. Presumably this is VS' way of saying that App_Code is not where you should put your app code, reasonable as it may appear.
The solution is to right-click on each file and reset "build action" to "compile". This also has to be done whenever you add files. Or you could submit to VS and put your source somwhere else.
< /frustration>
Since it's late and over 3 years old. I came across a similar issue. The solution above is perfect.
With newer VS IDE versions, go to App_Code file's properties and update the Build Action to 'Compile' if it's set as 'Content'. Using App_Code folder may be outdated in newer VS versions but some older developers still use the folder.
Replace vbproj and vbproj.user with your backup
My issue wasn't the App_Code folder in particular, but I was getting "not defined" errors in my Errors List until I double-clicked to open the file, then references would resolve and that error would disappear without me doing anything more, but when I tried to rebuild, all these errors would appear again.
The only real clue I had was that they were all related to the same project and when I dug through my Output window, I could see there was a conflict on the .Net framework versions. Once I resolved the version difference, the errors disappeared.
I was getting this issue for a slightly silly reason, but it might help for others to learn from my pain. :D
I was making the changes to the code in a tab of my test program, but that tab was for a VB file in a DLL I was using. Since those changes weren't being made/compiled in the DLL, it wouldn't find the class no matter how hard I tried until I opened the DLL project, made the changes there and rebuilt the DLL.
I had the same issue in Visual Studio 2019 but the .vb file already had "Compile" in properties > build action
I had tried rebuild, clean, deleting the file.
If I copied an existing class into this folder it would also not be recognised
Closing visual studio and restarting it fixed the issue, so there's a bug in VS where it doesn't compile files in a new folder until VS is restarted

Errors while compiling asp.net website

Hey guys,
i have a website, i want to place the compile code on the production server, now i took the code on the local machine and trying to compile source code on local machine, but whenever i compile the code, in one of my control(ascx.cs) file i am getting error that the control does not exists in current context, i checked everything, Inherits, CodeFile, even in the code behind(.cs) file, everything is perfect, even i get the control id in the intellisense, when i remove the control and again add the same using intellisense, the errors gets removed but after i publish site, the same error comes again....
Please reply with some suggestion/solutions.
I've had this issue before when referencing another project. It would give it intellisense, but then trying to compile would cause errors and take away intellisense. Removing and re-adding it would give me intellisense back.
The problem ended up being the target framework. The project was referencing .NET 4 Client Profile, whereas the project it was referencing was just .NET 4. Apparently this difference is subtle enough to trip up visual studio in the confusing way described above.
So take a look at your project's target framework, maybe you'll get lucky.
Definitely check your Inherits or CodeFile. I've had this happen before where I had them pointing at the wrong files.

Resources