F# application keeps disconnecting C# Assemblies - c#

I have an F# application that references a C# assembly (in this case as a project in the same solution) in order to use an existing C# code base. The problem is that every now and then, the F# project seems to go fubar and not recognize the referenced C# assembly, giving me a "The namespace or module 'HCGInterfaces' is not defined". The C# Assembly compiles just fine. I have rebuilt/cleaned the solution, deleted the dlls, removed and re-added the reference and nothing seems to work. The only way that I can get the application up and running again is to delete the F# project and re-add all the F# files. Any idea why this happens and how to stop it from happening? Rebuilding a project from scratch each time is not a really fun option.
Thanks for your help!
[Update] I was able to get my project working again (although I don't know how or why), but now it won't recognize another C# library that I have referenced. In this case, it will not recognize any classes in it, only the interfaces that are part of the library. Very strange. I haven't been able to find anything about this issue, but I'm getting really frustrated with F# (or at least Visual Studio) at this moment!

Related

Newbie question about visual studio references

What is the use of the "References" list in my visual studio project? Why I can still get my project compiled and run it even though I remove all of the references?
When I create a new c# console project, it has a hello world template program, and the References list contains certain references from .Net I think. I removed all of them and the template program still work, why?
The template program has a bunch of usings that were in the references of the project so I thought if I remove all of them nothing will work, but the project still compiled and ran.
This seems to be a very simple question but I can not find anybody answering that online.
Say you need to create an image processing app. But you don't want to, or rather won't be able to create a JPEG encoder/decoder. So you will find a 3rd party library to do the encoding/decoding. And the 3rd party library needs to be put somewhere so that your project can find it. And that is the References folder (it is not really a folder).
Then you can use the 3rd party library's namespace in your own code. And it compiles. But if you remove the references, it won't because VS won't be able to find those namespaces.
If later you decide not to use this library, you will remove your using statement and all the relevant code. At this point, if you remove the references, your code will still compile because they are not used at all.
Ok to answer my question after some research and tests. There are indeed namespaces I can not reference if I don't add them into the References list, the ones that were still working after I removed references were the ones that are implicitly referenced by visual studio.
I have learned that from the links below.
https://learn.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2019
https://social.msdn.microsoft.com/Forums/vstudio/en-US/92a0c975-e350-4d8d-af8e-36ec0ad6c95c/specific-purpose-of-mscorlib-dll-in-net?forum=clr

The type or namespace name does not exist in the namespace ''are you missing an assembly reference ?"

I have a solution that worked fine until the last couple of days which contains around 15 projects that are DLLs or Webforms applications. I also use ReSharper which is another peculiarity related to this solution.
There are naturally projects referencing other ones within the solution and all but one compile independently and run OK except one Webforms app (A) that refers to namespaces within another Webforms app(B) DLL.
(A) has 7 exceptions when I try to debug this all along the lines of "the type or namespace name [MyClass] does not exist in the namespace '[(B) namespace]' (are you missing an assembly reference?)"
All the projects target the same .net version 3.5 all target the same processor CPU architecture, I have cleaned the solution, recreated the reference to (B) from (A), can see the namespace in the object explorer when looking at it from (A)\bin so it's there... but still (A) at build has these errors above and for over a day now I cannot for the life of me work out why... can anyone help?
If I run the Webform app (B), it builds and runs without a problem...
The mention of ReSharper is due to it also not working with this solution anymore (but does work with others solutions), the behaviour of ReSharper with this solution is that I cannot type characters into VS anymore unless ReSharper is suspended. Also when searching for types the list does not filter down at all - so there is some sort of corruption there although I have cleared caches related to ReSharper.
The problem might be your virtual directory in IIS, it was not pointing to the correct folder, so the page couldn't find the DLLs
Brad McA, have you unblocked that namespace? In REFERENCES folder, right click on the particular reference, and see if there is an option "Unblock", If u can see it, kindly unblock it. Thanx
Seems to be building now, reason for failure was a dependency on Newtonsoft.Json.dll which was built to target .net 4 (strange as this reference in (B) has been there for ages! why it would suddenly cause build issues).
Thanks to those who posted, have a lovely day.
the dll reference were origionally built in framework 4.7.1. when trying to add the reference in lower framework project say 4.5.2. It gives such errors. try to update your project framework from 4.5 (lower version) to the version of your reference.

Visual Studio failing to detect existing objects, even from within the same file. Project still builds

I just reopened a project I haven't touched in a few months, and my copy of VS2012 is doing some strange things. I've seen it do these things before, but usually it works itself out after a Clean or after restarting VS.
I have a Common project, which is referenced by at least 2 other projects in the solution. I have a cs file that contains 2 enums, and a class. I reference those enums within the class, but VS gives me the little red underline that indicates a syntax error.
"The type or namespace name "SourceTypes" could not be found (are you missing a using directive or assembly reference?)"
The enum is literally located above this class. It is public. Also, if I do a build, it will build correctly. But the error comes back after the build finishes. Sometimes it doesn't build properly, and I have to build this project first without doing a build all. I have no idea why this reference has started doing this suddenly.
I also installed CodeMaid and AllMargins recently, but I don't think either of those could cause build errors.
Also, the common library is using Framework 3.5, because it is referenced by two other projects, one of which is SharePoint, and therefore 3.5, and the other of which is a WPF app, running 4.0 (not Client Profile)
Any ideas?
Update: Clearly the problem is that it doesn't recognize the namespace. In the using statement in multiple files, the namespace has the red line under it. Maybe I've got some kind of namespace conflict? But if I did, I would expect it to fail when I do an actual build, which it does not.
Solution: Feri got the right answer. By unloading the Common project, and then reloading it, the problem went away. All references to the namespace were corrected, and everything works smoothly again.
Solution: Feri got the right answer (but opted not to submit his solution as an answer). By unloading the Common project, and then reloading it, the problem went away. All references to the namespace were corrected, and everything works smoothly again. However, the problem seems to come back whenever I close/reopen VS. Unloading/reloading the project fixes it each time though.

Difficulty loading references after their rebuild

I'm writing applications and libraries simultaneously, and whenever I update a library it's a bit hard to get it recognized in the consumer application. I have open a separate Visual Studio instance for each library and application. After rebuilding a library I get in the consumer applications the warning/error below. I then either have to remove the reference and add it again. Or I have to clean and build the library solution 3-4 times, for such warning/error to disappear in the consumer app VS solution. Why would doing that 4 times make any difference to doing it 1 or 2 times..?
Would like to understand why this happens and if something can be done to make this work more smoothly?
Not sure if it's relevant but most of my applications I write in VB.NET and libaries in C# (as I'm in progress of changing everything to C#). I also have C# files from the libraries open in the consumer application VS, as it pops up during debugging. I also reference library dlls in the library project /bin/Debug folder, because I'm making a lot of changes at this point of development.
Warning 1 Namespace or type specified in the Imports 'somelibrary'
doesn't contain any public member or cannot be found. Make sure the
namespace or the type is defined and contains at least one public
member. Make sure the imported element name doesn't use any
aliases. 'local path'
..
Error 72 Unable to load referenced library 'path\somelibrary.dll': The
process cannot access the file because it is being used by another
process.
I'm writing applications and libraries simultaneously, and whenever I update a library it's a bit hard to get it recognized in the consumer application. I have open a separate Visual Studio instances for each library and application.
This is the fundamental source of your problem. Visual Studio does not like it when things outside it's control change. You should have a single solution open with all the relevant projects included in it. Then when something changes, all the projects which depend on that project will automatically be rebuilt. (At least, that's the default.)
After rebuilding a library I get in the consumer applications the warning/error below. I then either have to remove the reference and add it again. Or I have to clean and build the library solution 3-4 times, for such warning/error to disappear in the consumer app VS solution. Why would doing that 4 times make any difference to doing it 1 or 2 times..?
I don't think it has anything to do with how many times you clean and rebuild it, but how long it's been since you last made a change - you have to wait long enough for the VS instance building the dll to release the lock on the file, before the VS instance that is using it is able to access it.
When you build a project you lock up the .DLL file in the project you build it from, because that is the version of the assembly that the library instance of visual studio will use - however you are referencing that very same library in another process hence the reason you are seeing the error.
You have two options, keep having two instances and then close the two instances open them again and it will be fine.
What you are better off doing is adding the project itself you are referencing (and are getting the error for) to your solution. Then instead of referencing YourProject/bin/debug/assembly.dll add a reference to the local project via the Projects tab. This will then keep one process referencing the appropriate assemblies that it needs.
For every project in the solution check the project settings -> Compile tab -> advanced compile options... -> target framework(all configurations), see if they are all (for example) .NET framework 4. having different or the wrong framework might cause the problems you're having right now

Adding reference in c# project...but it "goes away"?

I have this c# project...i add this reference (a dll) to it, and try to use that library in my code.
I use what its called (its a database connector)
MiDB myDb;
it doesnt find that, i can right click and say "resolve" usings... that adds this line to the top:
using ThePackage.Database.AoNM.MiDB;
blah blah
So this works, it sees it, i can even then call a method that is seen:
myDb.InitDB("stuff here");
bingo. the minute I build this, it says it cannot find ThePackage, and its like that usings, or reference doesn't exists. In the solution explorer it is still there? I can remove the reference and add it again, and then this same thing happens, it "seems" like its there, but going to build and run it "goes away".
It might be cause its late, but I am honestly totally lost as to why C# (2008) is doing this to me?
DLL was built in 2008 to... maybe im missing some build option with the dll?
Check that the dll and the assembly run on the same CPU type (x86-x64). I used to have similar errors (and very strange error messages) when they were different.
I had same problem.
You need to change target framework of your project from ".Net Framework 4 Client Profile" to ".Net Framework 4"
It worked for me.
if the dll is using a higher .net framework version than the application, you would see this. it's probably unlikely the way i read what you said in the comment in that the application is in visual studio 2010 and the dll was built with visual studio 2008. not completely sure that's the case, though, as the quesiton cites visual studio 2008. anyway, check that you are using the same framework version or greater in the referencing project as in the referenced.

Categories