Missing System.Windows - c#

I have a rather large solution with some Silverlight and WPF projects inside it, as well as some class libraries and other things.
One of the project is a class library that references a SilverLight application which references System.Windows
But at runtime, I get the error:
{"Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"}
I looked in the GAC (C:\Windows\assembly) and couldnt see it in there...
Whats happening here?
The reference is to: c:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll which DOES exist.

Sounds to me like your WPF app is loading a class library that references a Silverlight assembly. That cannot work, cats and dogs. If an assembly is referenced by both a WPF and a Silverlight app then it has to be compiled twice with different framework assembly references. That takes two projects. Keeping the WPF and the Silverlight stuff separate in different solutions is the best way to keep out of trouble.

I've seen similar errors in two cases that might apply here:
When an assembly I reference required an assemble I have not referenced . . . in this case that would mean System.Windows is using something else you need to add a reference too.
The more interesting case is when VS2010 auto selected ".Net Framework 4 Client Profile" for me when I actually needed ".Net Framework 4" (no "client profile"). Select the project properties and see what your setting is.
Frank
Per you request additional instructions:
Open Solution in VS2010, right click the project in question (not the solution line) and select "properties" from the bottom. In the resulting GUI, select the "Application" tab and make sure "Target Framework" does not have "client profile" in the name . . . that is should be ".NET Framework 4" not ".NET Framework 4 Client Profile".

I have not found this solution anywhere else, but stumbled upon it as a trial-and-error-by-fire...
The error message was a bit misleading in my situation. The tip off was that it wasn't really the "System.Windows" assembly itself, but one of the dependant assemblies.
What you may want to do is to check your GAC and see if one of these assemblies are in it:
System.Windows
System.Windows.Controls
System.Windows.Controls.Toolkit
System.Windows.Controls.Layout.Toolkit
Try removing them from just the GAC, then do your rebuild. If it doesn't work, just open two windows explorer windows and copy them back from either the c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll folder or the folder for your Silverlight Toolkit and you'll be back to where you started from.
Here's what I suspect is happening:
The Visual Studio 2010 compiler is getting confused about where to get those referenced assemblies when doing the build because the GAC assemblies always takes precedence over another copy of an assembly (even the reference assembly folder that VS2010 uses). So even though the assembly is technically correct with the same ID key and everything there's something with the VS2010 compiler that can't determine which library to use for building and it will refuse to complete the build.

mmmm sometimes you put your classes in different project for example you can create a project for viewmodels , if is this the case then you need to reference PresentationCore.dll , this is the dll that give you access to System.windows so you can use ICommand for command bindings

Related

Why do this occurs "Could not load file or assembly.." in C# class Library

I'm newbie to .net projects. Although I was able to code in c# & use it's frameworks, Some times I face exceptions which I really didn't get any proper resource/suggestion to modify or rectify them. Hope I would get clear this time.
The exception which I faced is as follows :
Could not load file or assembly 'Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
I'm really confused with such type of exceptions. What's the reason for those & how we needs to cross check to clear those ?
Here is what I did install: "Microsoft.AspNetCore.Cryptography.KeyDerivation" from nuget console with version 2.2.0.
My installed packages list image :
The main reason for this type of error is a result of your output folder. Take a look at where your binary outputs were placed. Inside of that folder (usually your .exe or .dll output, not sure what kind of .NET project you're writing), you should also have all of your dependency dlls. In this case, the dll related to Microsoft.AspNetCore.Cryptography.KeyDerivation is missing. So when you go to run your executable, it complains "Could not load file or assembly KeyDerivation" because it couldn't find it.
To resolve this issue, double check your project's references and that there are no issues with the Microsoft.AspNetcore.Cryptography.KeyDerivation reference (what I mean is, make sure there are no yellow exclamations or other icons showing up next to this reference in your Solution Explorer). If you have any issues, remove the reference, then add the nuget package again.

Could not load file or assembly NLog

Error: http://pbrd.co/1vTqOTb
I am getting an error in my XAML in my WPF project:
"Error 11 Could not load file or assembly 'NLog, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies.
The system cannot find the file specified. MainWindow.xaml 73 9 TestApp"
I have searched the entire solution and cant find any 'NLog'
I have tried to add the NLog dll to each of my projects in the solution but it makes no difference.
Any idea?
Turned out to be the NLog was .Net 4.0 and the project was .Net 4.5
I changed the project to 4.0 and the other dependent project to 4.0 and its working.
Thanks!
Whenever you reference another library, there's the chance they will need some other library. When you reference WPF, there are a lot of underlying libraries that get pulled up.
First, make sure that the DLLs you've referenced are set to "Copy Local = True" under their Properties. Also make sure they have the same PublicKeyToken as your error - if they're referenced by strong name (and most of .NET is) a slightly different version won't be read as the correct file.
The other thing you should consider is checking whether the DLL exists in your GAC, and manually installing it if it doesn't. This can often be the cause of such frustrating errors due to a misinstalled sdk (I once has the same issue with the Blend libraries)

Could not load file or assembly 'System.Drawing, Version=4.0.0.0

I installed Monogame, and when trying to run a very simple hello world style game I get this exception. I understand that there are several posts on stack overflow regarding this error, but am still puzzled as to how to fix this. Do I need to uninstall .Net and reinstall a different version? If so, how do I do that?
A System.IO.FileNotFoundException was thrown.
Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
Here's a downloadable link to the Xamarin Project:
https://www.dropbox.com/s/q7quw26lg1etdts/MonoGameTester.zip
Such errors will occurs if you have reference to assemblies that do not ship with Xamarin.iOS. That's the case for System.Drawing.dll.
In your case it's likely because your project has references to both monotouch.dll and MonoMac.dll and that's not gonna work.
You need to build separate projects for each target, i.e. one for iOS (monotouch.dll) and one for OSX (MonoMac.dll).
From each project you can share source code and/or assemblies (for shared logic). Both projects also need to include platform specific code and references.
You end up with a lot of shared code (in source or assemblies) with a few platform specific bits of code.
I ran into the same issue and above suggestion didn't worked for me, so I did the following :
Open you Project
Go to the Solution Explorer
Expand the Reference group
Delete the System.Drawing reference
Right click on Reference group
Add Reference
On the ".NET" tab, search for System.Drawing to add the right reference

Can't Load Assembly (.DLL) that's visible in References

As shown in the screenshot, VS 2010 is failing to load my OAuth reference despite the fact that it is RIGHT THERE in my References folder. What am I doing wrong? I have already restarted VS 2010.
Thanks for your help.
An assembly (the DLL) does not necessarily need to use the same names for namespaces as the DLL name. This means that your assembly (EvernoteOAuthNet.dll) may use a completely different namespace structure, ie: Evernote.OAuth. You can double-click on the assembly in References to view it in the Object Browser, and inspect what types it contains, including their namespaces. This may help you pick the right namespace for your using .
The problem was VS 2010 was deleting the assembly every time I would try to build. I found the solution:
You need to change your target framework from ".NET Framework 4 Client Profile" to ".NET Framework 4"
Ref. http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/1537c41b-52b9-4e47-91b2-2e38b8fdfbfa/

Cannot use external references with C# Console Application

I have tried all the suggestions below but still no joy.
I'm now trying a console application, and let me explain exactly what I'm doing.
I create a new console project in VS 2010
I add a number of references (dll's) some that aren't mine such as Castle.Winsor and N2 CMS dlls
in the console app I can add using statements indicating I am using name spaces within the referenced DLLs
I start writing code.
As soon as I compile all the code that uses the referenced DLLs immediately complains with "The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)"
I have tried setting the dlls to copy to local always, I have copied the DLL into the same directory, I have tried added reference by project and adding a reference to the DLL's themselves
I don't get this problem with a web application project or a ASP.net project they always work fine, only something that is compiled to an EXE like a console app or windows service.
there must be something I'm missing or I would have got this working by now.
Change the project Target to a non Client Profile target. Right click the Project and select Properties, you should see a list of Framework versions. As you are using VS2010, the Console project you've created by default targets .NET Framework 4.0 Client Profile, change that to .NET Framework 4.0.
Check if Copy Local is set to true for the referenced assembly.
First, as to your question, its hard to know exactly what you're doing wrong, but from the fact that you're using an underscore in an assembly name (and probably in namespaces and type names), it suggests you're rather new to the .NET world.
This suggests that you're adding references to other projects in your solution by browsing to the compiled assembly, rather than by adding a Project Reference. When adding a reference, you must select the Project tab rather than browsing for the assembly.
Even if you don't believe this is the issue, remove all references and re-add project references to make absolutely sure. Assumption, asses etc.
Once you've done that, I'd strongly suggest remove all the underscores from your types, namespaces and assemblies. You might want to go read the framework design guidelines, too.
Open your .Proj(Windows service project file) file in notepad and check whether your assembly location(data_object) is the same which you are pointing.
When you open .Proj file in notepad you can check for,
Project reference,
<ProjectReference Include="C:\StackOverflow\StackOverflow.csproj">
And if you giving dll or exe refrence then
<Reference Include="StackOverflow, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<ExecutableExtension>.exe</ExecutableExtension>
<HintPath>C:\StackOverflow\bin\Debug\StackOverflow.exe</HintPath>
</Reference>
I suggest you to give exact location including drive name like above example.
Other option you may try,
1. Clean and rebuild
2. Add Project reference if you already tried dll reference
3. Check whether the folder (referred assembly location) is Read Only then remove it.
In VS 2019, I had two projects, one C++ and other one C# Console in one solution file. When tried to add a dll reference through "Add reference", I was not able to see Browse button in "Reference Manager" window, to select dll file.
But when I created only C# Console app inside solution then I could add dll reference.

Categories