Reference Component could not be found - c#

i'm trying to develop an application but then these warnings popped out. I have tried disabling my anti-virus (Avira) but it still won't work.
Warning 1 Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'MyAssembly.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. ConsoleApplication1
Warning 2 The referenced component 'MyAssembly' could not be found.
Can anybody please help me? Thanks!

What .NET runtime version is your application being developed with?
If the error is to be trusted, your project is say a .NET 3.5 (2.0 runtime) project but the MyAssembly library is developed in .NET 4.0 resulting in the error you see.
You cannot reference newer runtime version assemblies in an older runtime version project. You'd have to "upgrade" your project to at least match the framework version of the assembly given to you.
Right click on your project file and choose properties. Depending on what version of Visual Studio you are using this screen may look different, but go to the application tab and see what the target framework is.
Then go to the assembly you referenced in your references and check the "Runtime Version" in the properties section:

Related

Trouble with "Assembly File Selector" Dialog Box

I am getting this error message on one of my development computers:
Assembly File Selector
The following assembly name can not be resolved automatically.
System.XML, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Please select the assembly file manually.
The error is happening on a new computer I just setup. This error does not happen on any of the other computers I have used my program on.
The program uses .NET Framework 4.8. I have installed that framework on this computer. I am both building my program and running it on this computer.
Nothing I do with the dialog box seems to matter. My program works fine if press OK or cancel. Selecting a file does not prevent the dialog from appearing again.
I assume there's some configuration step that didn't happen right on this new computer. What can I do to track down what is going wrong?
That is a very old version of System.Xml - .Net 4.8 would have version number 4.0.0.0. If you are not intended to use an older version of .Net, verify your references are not set to "Use Specific Version" and that your project is targeting .Net 4.8.
That dialog looks like something from Redgate Reflector, which implies you are working with existing assemblies. In that case, you might check the version of the reference in Reflector to confirm.
Do you have the same versions of the older frameworks installed?
I was able to solve the problem thanks to hints from Mitch and Simon Mourier.
My specific application is an add-in for a program called Revit. During development, I use another add-in to load my add-in. I was using an older version of the other add-in. For whatever reason, on this specific computer, it was throwing this error. I am using the same old add-in on other computers with no problems.
I replaced the other add-in with the most recent version and it works correctly.
I looked at the referenced for the old add-in. I referenced the latest version of System.Xml (4.0.0.0). There were no references to System.XML version 1.0.0.0. I never did track down why that was specifically being ask for.

C# compiler can't find custom dll reference

I have written a small ORM assembly for private purpose and wanted to check the connection string.
I had created a console application and add a reference to the assembly as I always did.
Project explorer has no warning with the file, object explorer sees all my types and namespaces in the assembly. But compiler can't resolve this reference for some reasons and I don't understand why.
I restarted Visual Studio (Express 2013) but it did not help.
Can somebody get an idea why it can't resolve that assembly reference?
My problem was in different versions of .Net: .dll had been complied for .NET 4.6.1 and Project for .NET 4.5.
I have checked the properties of a dll and there was 4.0 runtime version setted so i was sure that version is fine.
Only compilation warning helps me to realize the reason of this problem.
Unfortunatly i get used to skip them and didn't read it right after a compilation.

Referencing mscorlib in Visual Studio 2010

My target framework is .NET Framework 4.
The project is an MVC 3 project.
I'm using Visual Studio 2010.
Windows 7 64bit
I'm trying to get an old project working on my fresh install of Windows 7 64 bit. When I try to compile the project I get the following error multiple times:
Error 11 Missing compiler required member 'System.Runtime.CompilerServices.ExtensionAttribute..ctor'
I have read multiple questions on this same error but none of the solutions seems to work and are related to other target frameworks or different versions of MVC. Even more frustrating this exact same project compiles perfectly on my co-workers computer.
From what I understand, the reason I'm getting this error is because the project is looking for System.Runtime.CompilerServerices in System.Core but it was moved to mscorlib.
I am trying to re-ad mscorlib but when I try to add it as a compiled reference I get the following messages:
When I try to add mscorlib.dll 2.0:
A reference to 'mscorlib.dll' could not be added. The ActiveX type library 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb' was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead.
When I try to add mscorlib.dll 2.4:
A reference to 'mscorlib.dll' could not be added. The ActiveX type library 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb' was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead.
So when I try adding mscorlib v4.0.0.0 as a .NET reference I get the following error message:
A reference to 'mscorlib' could not be added. This component is already automatically referenced by the build system.
Am I missing a specific update? Do I need to re-reference mscorlib? If so how do I go about that? Is there a way to get the project to work with a System.Core.dll instead of mscorlib?
After some help, I have uninstalled .Net 4.5 and installed 4.0 which allowed for the project to compile, however I received the following error:
Could not load file or assembly 'Microsoft.VisualBasic.Activities.Compiler' or one of its dependencies. An attempt was made to load a program with an incorrect format.
To fix this, I then had to reinstall .Net 4.5 and reapply VS 2010 SP1. The project is now working!

Do i have to recompile a .dll in order to use it on a Mono Android Project?

I have recently acquired the student licence of Mono Android from Xamarin.
After making a simple project, i decided to start using some DLL's i am familiar with such as Json.Net and H.A.P on my Android Application (mono project), and that's when the problems started.
After trying to pull those references from NuGet, they failed since the "Android Application" project is not known leading to no .dll installed (NuGet tries to match the project type with the correct .dll to be downloaded be it WindowsPhone, .NET4, .NET 3.5 and so on).
So i moved on to mannually referencing the libraries, since i have them downloaded on my PC. Referencing Works, but as soon as i try to access the HtmlAgilityPack it raises an exception.
Error CS0012:
The type 'System.Xml.XPath.IXPathNavigable' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Xml, Version=x.x.x.x, Culture=neutral
The exception is raised on the first execution of the code because of J.I.T compilation of .NET, i know this.
Question:
How can i use my "so loved" .dlls on my Mono Android Project?
Do i need the source code of those libraries in order to use them on my projects?
Thanks in Advance
In order to recompile an assembly you will need the source.
To see what assemblies are provided by Xamarin.Android and Xamarin.iOS you can visit these two pages:
http://docs.xamarin.com/guides/android/advanced_topics/assemblies
http://docs.xamarin.com/guides/ios/advanced_topics/assemblies
One way to recompile it would be to make a Android Class Library or iPhone Class Library and add a link to all the files in the original source and then compile it. Or when Xamarin have their PCL support done, do something similar just in a PCL so that you have one DLL targeting multiple platforms.
You may also find this post useful, which briefly describes how to compile HtmlAgilityPack against Xamarin.Android: http://forums.xamarin.com/discussion/comment/2139/#Comment_2139 You might need to alter some things as this is from December 2012, since then things might have changed.

critical runtime error after upgrading application with .NET assembly dependencies

I am upgrading an application and running into some issues with it.
Now the old application was version 1.0 and loading a depedency assembly A at version 2.1.1 The assembly is present in application local directory.
I am upgrading the new application to version 2.0 that will load assembly A version 1.0.1 which is present in its application local directory. I've checked application references using ISpy and confirmed the new application references A version 1.0.1
But when I start the new application (v 2.0), it is still trying to load assembly version 2.1.1 and failing. I checked the app.config, machine.config and GAC and there is no redirection for version of assembly A. I also checked fusion log files but don't see any redirection. All I see is the fusion log is that application prebinds A at version 2.1.1 and hence fails to set up the assembly present in its local directory.
Is there something I am missing here? What could be the possible reasons for application still referencing the older assembly at runtime?
Update: Using some tools, I realized the the older assembly is being referenced from a native DLL that is referenced by my application, but I don't know which third party DLL is that, and the application loads a ton of them. The fusion log confirms it by logging "Calling assembly : (Unknown)." for the missing assembly.
Now my next step is to find which dll is referencing the wrong assembly and fix that. Now the problem is that ILSpy tool doesn't show the native DLLs references, and DLLDepends tool does not show the assemblies references, so I am not able to link the two.
thanks
Since the library your trying to reference is supposed to be apart of the GAC; you may want to try:
Control Panel
Small Icons(Administrative Tools)
Event Viewer
Application
Windows itself should throw an exception with some particular details it's attempting to reference when it has an error. Especially if it's apart of the GAC. It was more helpful for me to hone in mscoree.dll and mscorelib.dll libraries fairly easy. Granted those clients that I used that for had corrupt framework; but Event Viewer told me the exact library that it had an issue with.
You may want to try that. Not sure which library; but keep in mind this is usually beneficial to libraries that are found within the %windir%/Assembly folder. Hope that helps.

Categories