Referencing class library (.dll) from the same VS (2010) solution - visual-studio

recently I have experienced a problem which is really strange. I have a c# VS solution which contains 2 projects: a class library (.dll) and a WindowsForms. I had no issues so far to reference the dll from my WinForms applications. However, now, after I reference it, everything works fine, in terms that while writign code the dll assemblies are recognised, until I try to compile and debug, where the dll is not recognised any more, though it is referenced.
Any help would be apprecited.
Regards,
D.
PS. I have tried both referencing the project and dll...Does that mean that the problem is at the dll?

do you have correct .net target on both sides ?
.net client profile / full .net

Related

Referencing DLL from GAC in Visual Studio

So I've looked around to try to find some posts on this and there are many but none that address my specific question (that I could find).
I am trying to add some DLL's in my project but few of them are coming from :
C:\Windows\Microsoft.NET\Framework\v3.5\XXX.YYY.dll
and what I expecting this should be coming from GAC.
Please suggest me the best practice to reference the Dll's in Visual Studio.
That's not the way it works. When you use Project + Add Reference then you always add a reference assembly. This is never an assembly from the GAC. The GAC is a runtime implementation detail, it is only ever used to supply assemblies when your program executes, never when it is built.
It is very important that it works that way, the content of the GAC on your machine will not match the content of the GAC on your user's machine. Lots of DLL Hell countermeasures are in place to ensure the mapping of your reference assembly to the user's GAC content is taken care of with good diagnostics when the user's machine isn't configured correctly to execute your program.
This is also the reason that you cannot directly look at the GAC folders when you navigate to c:\windows\assembly with Explorer. A shell extension handler hides the details to stop you from making a mistake like adding a GAC-ed assembly as a reference assembly. This same extension handler is not installed for the .NET 4 assemblies, you can look at c:\windows\microsoft.net\assembly and see the structure of the GAC. Do not assume that it is now okay to add references from there, reference assemblies are even more important in .NET 4, they are completely different from the runtime assemblies.
So seeing the reference assembly stored in C:\Windows\Microsoft.NET\Framework\v3.5 is completely normal, that's the home directory for .NET 3.5 specific reference assemblies, like System.Core.dll. For .NET 4 projects the reference assemblies are stored in c:\program files\reference assemblies, they should not reference C:\Windows\Microsoft.NET\Framework\v4.0.30319. Check this answer to see what kind of undiagnosable misery can be caused by not using the correct reference assemblies.
Those assemblies are assemblies of the .NET Framework 3.5. The assembly cache is located at
%SystemRoot%\assembly
You may distribute the .NET Framework 3.5 (scroll the the end of the page) together with your project. Aso if you are using VS Setup projects you can simply use the properties page to reference it.
To reference those assemblies you can easily right-click "References" > "Add Reference" and choose the assembly from the .NET tab. For referencing GAC assemblies refer to this question.

How (practically) to reuse an existing .NET library in MonoTouch

Let's say I've got an existing .NET assembly built in Visual Studio 2010, which is consumed in some other Winforms product. It has no third-party dependencies.
I want to reuse that library directly in a MonoTouch solution.
As it stands, to be able to add a reference to my library from within my MonoTouch UI project, I have to create a new csproj file and create links to all of the source files within it.
This works but is a maintenance burden. There must be a better way?
Thanks in advance.
As of today you need to rebuild your assemblies. That's because they'll be linked to monotouch BCL (e.g. a different mscorlib.dll) which a superset of the base class libraries (BCL) shipped with Silverlight.
Hopefully newer release of MonoTouch (and Mono, Mono for Android...) will support the new "portable library" which would make it easier to share compiled binaries across frameworks.
http://blogs.msdn.com/b/bclteam/archive/2011/01/19/announcing-portable-library-tools-ctp-justin-van-patten.aspx
Believe it or not, you actually can reference a .dll lib built in VS.NET as long as your shared assembly is not referencing any other assemblies that would make it incompatible with monotouch. I currently am doing this on our project. The referenced .dll only has dependencies on System and System.Core and its basically just a set of POCO's. I'm sure someone with better knowledge can tell you exactly what it would take to make the .dll incompatible. Even using an incompatible API call within System or System.Core could break it per poupou's answer but if you keep your shared .dll dead simple it should work.

What do the red exclamation mark icons in front of references mean in VS2010?

In Visual Studio 2010 project property pages, if I select Common Properties and Framework and References for a C++ project, I can see all the references from a project.
They usually have this icon:
Sometimes, though, some references appear as this:
I tried to google it or find any documentation about it in the msdn documentation about references, but cannot find anything related to this. Does someone know about this? Thank you very much in advance!
This happens also if you had VS2010 SP1 and then install .net 4.5. They changed the handling of this in a way that causes problem in VS2010. (.net 4.5 is installed with VS2012)
I believe it is because the referenced assembly is a different version than your target application. I receive the same thing if I reference a .net 4.0 assembly from a .net 3.5 project.

Using VS 2010, can I reference a project created in VS 2005?

Here's a puzzler - something that doesn't work that I assumed would (no surprise there).
We have a library project that is referenced in a few other desktop app projects. The library project is written in VS 2005 (.NET 2.0).
My problem is that some of our apps still live in VS 2005 for the time being (for various reason). I can't seem to reference this library project in VS 2010 without it demanding that I upgrade it to .NET 4, which if I do, then breaks my ability to include it as a reference in my VS 2005 projects.
This type of thing fries my brain. Is there any way I can make this work?
Hmm, that doesn't make a lot of sense. You don't reference a 'library project', you reference the DLL that it produces. Project + Add Reference, Browse tab. There's no known problem with that, within a 95% accuracy guess, mixed mode assemblies have a few hairs.
If you actually try to load a vs2005 project into a vs2010 solution, then yes, it's going to try to convert the project file. And that turns vs2005 catatonic, it doesn't have the time machine to guess what a vs2010 project looks like. Just making a copy of the project directory solves that problem.
Can you change the .NET version back to 3.5 or 2.0 in VS.NET 2010 after it revises the project version to .NET 4.0?
Use a file reference to the built dll, rather than a project reference.
You may also find you need to add an extra bit of compatible-framework info to your manifest file to tell .net to allow your .exe to use .net 4 and .net 2 assemblies alongside each other - if it's not there you'll just get an error on startup. (Sorry, I can't remember the exact details and I'm not at my work machine right now to be able to find them - but if you have problems at runtime, the error message should lead you to the exact solution you need)
Correction: I was thinking of this 'useLegacy' startup setting, which you may need to add to your app.config if you want to use a mixture of .net 2.0 and .net 4.0 assemblies in your application:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
On option, that is a complete PITA, but should work is:
Create a new project file in 2010 that includes everything the 2005 project file has. Just call it MyProject2010.csproj or whatever.
Then, add this project to your 2010 solution.

Assembly reference not getting updated in the silverlight 4.0 application project

Point 1):
In one solution called CustomBehaviorsSolution, I have two projects - one is class library and another is silverlight class library project. The silverlight class library project has the class files which are 'linked' to the files of the first project. The solution compiles successfully.
Point 2):
I have another solution which has one silverlight application project and another desktop application project. The silverlight application project has the assembly refernce of the silverlight class library mentioned in Point 1 above. The desktop application project has the assembly reference to the class library mentioned in point 1 above.
Now, when I modify or add any class to the project mentioned in point 1 above and update their references in the projects in the solution 2; I experienced some weird behavior.
The desktop application project gets the new changes from the referred assembly whereas the SILVERLIGHT application project does not get the same changes from the referred assembly.
In ILDASM i saw the referred assemblies of point 1 above and they are alright. The problem is that the silverlight application project is not reading the updations from the assembly reference.
Can someone please help?
(I have been removing and then adding the assembly references.)
I'm using VS 2010 and Silverlight 4.0. (After ensuring almost everything, now I think that it might be a bug in VS 2010 or SL 4.0 ! Possible?
I created the new solution altogether (mentioned in point 2) and then added necessary assembly references and now everything is fine.
It seems that the previous solution was corrupted due to some reason.

Resources