I have 3 projects - silverlight app A and 2 silverlight class libraries B,C. My serialization logic is in project C, Method CallSer(). If the routine from B calls CallSer(), everything works fine. But if routine from C calls CallSer(), it gives the below error. I have tried setting Copy Local property but it's not helped (I am seeing the assemblies getting copied to the debug folder when Copy Local = True). This seems to be surprising, any one has ideas on how to resolve this? Thanks.
{System.IO.FileNotFoundException: Could not load file or assembly
'System.Xml, Version=5.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The
system cannot find the file specified. File name: 'System.Xml,
Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'}
Update: I did a little more analysis and found the call to CallSer() is actually from another .NET class library D. So call stack shows is D -> C -> CallSer(). I am not sure what difference this can make as long as I have System.Xml.Serialization reference to C. Also, I don't see System.Xml.Serialization listed in Add Reference option for D? Why is that so?
Update: Looks like XmlSerializer is getting confused as to which reference to load.That's because Silverlight has XmlSerializer defined inside System.Xml.Serialization.dll assembly and .NET framework has it in System.Xml.dll. My project D has reference to System.Xml and C has System.Xml and System.Xml.Serialization. How do I make sure C always references Silverlight version of dlls?
I came across the same issue trying to run unit tests, the problem is that if the code that is calling the Silverlight Class Library is built against the "desktop" .Net Framework you will get the conflict as it will not be able to load the Silverlight version of the dll, only the Silverlight runtime can load dll's built against the Silverlight CLR/BCL.
Take a look at creating a Portable Class Library and the Portable Library Tool
I had the same problem with Xml.Writer.
I worked around it by sharing my source code file between my silverlight project and my non-silverlight project, using 'Add as Link' in Visual Studio.
I also had to use #ifdef SILVERLIGHT to have a separate namespace.
Lloyd's Portable Class Library approach seems cleaner but I didn't have time to try it.
Related
I have a class library in .NET Framework 4.7.2 and I use a reference to Newtonsoft.Json Version 12... something.
If I run the app as a windows application (there is a winform) everything works just fine. However, it is actually a class library that is being called by another program as a plugin. Inside that program I get however this error
Which translates basically to "couldn't find the Assembly...". There Version=12.0.0.0 is begin referenced and the dll in that particular folder (the plugin folder) says version 12.0.3.23909
I tried to clean the solution, delete every reference to newtonsoft I found etc. but the result is always identical. What am I missing?
Sorry if this question has been answered before, I searched dozens of previous questions, but I can't seem to understand what is going on appart from "redo everything", which doesn't work here.
UPDATE
The output bin is as follows
If I change the program to a windows application and run it by calling the exe, it works, but not via the other program where it should run as a plugin. Interestingly, the core dll is being opened and the baseform works, but not newtonsoft.
Change at least one of the versions. I mean:
Change the version of Newtonsoft of your class library to -> 12.0.3.23909 and then build the class library and use it as a plugin.
Or change the Newtonsoft version of your project to 12.0.0 and then use your class lib as a plugin inside it.
Or:
You can carry Newtonsoft (12.0.0) with your class library and load both of Newtonsft and your class library as a plugin. (this works too but you should be aware of Dll conflict between 12.0.0 and 12.0.3)
I have more than one .Net projects to work and i want to reference these all projects into one integrated project and add them as a reference in this project and want to run any method or function from this integrated project.So i have added all these projects in the same solution in the directory and added them to the solution and added as a reference.
Now My question
I havent converted those projects to class library as i want the main method to be there to kickoff that function from my integrated project ,if i make it class library will i still be able to access that main method???
I did add those projects reference and made them to class library and also as exe,but in both the cases , when i did import them ,but when i try to call those functions,it doesnt create an instance and doesnt show any options in intelligence,on top of that,once i try to build it back again,it throws an error "The type or namespace name could not be found(are you missing a using directive or an assembly reference?)"
Can someone please answer them !!!!
Internally there is little difference between a .NET exe and a .NET DLL. For most purposes a .NET .exe is just a .NET dll with some data saying "this class has the main function". It is one of those things they copied really well from Java and improoved upon.
There might be secondary differences (I am not sure the .exe provides full COM/.NET interop support, for example). But for most purposes, you can use a Compiled .NET exe like a compiled .NET dll. Including putting it into the references of a 3rd project.
The main issue here is that only the compiled code in the propert directory is considered. Especially if you still plan on working on those backend References, you need to be aware if you referenced the Debug or Release version of the .dll/.exe
I have to use a DLL as an API in my application (C#, .NET 4.5). I can reference the DLL normaly. No error at all. But if I want to use any class of this DLL, I get the following compile error:
Error CS1705 Assembly 'Assembly_X' with identity 'Assembly_X,
Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00'
uses 'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral,
PublicKeyToken=c878e80841e75d00' which has a higher version than
referenced assembly 'Assembly_YY' with identity 'Assembly_YY,
Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00'
Then i checked the DLL (Assembly_X) in ILSpy. The Assembly_X has two references to Assembly_YY: One with the version 12.3.0.0 and one with the version 65535.65535.65535.65535.
I tried the "bindingRedirect" in the App.config. But since the error occures during compile time this doesn't help.
I don't have the source code of Assembly_X or Assembly_YY.
How can I use this DLL or repair it?
UPDATE
The developers of the dll finally answered my call for help. The only work around they know of is to use Visual Studio 2013 instead of Visual Studio 2015 or 2017. It seems VS 2013 is not bothered by these double reference at all.
They write, that the error is created by a encrypting tool for the dll.
Thank you all for your ideas and help.
It looks like the first DLL is referencing a library which is a higher version than the other DLL you are using.
so you have 3 DLL's to consider: A, B & Bv2
Your project is referencing A & B
But A references Bv2 (an updated version of B)
SO when you go to use functions of A it throws an error because it finds B instead of Bv2.
The problem basically that you are referencing 'Assembly_X' which references assemblies 'Assembly_YY' versions 12.3.0.0 and 65535.65535.65535.65535 and you referenced only 'Assembly_YY' version 12.3.0.0 in your application and didn't reference 65535.65535.65535.65535
Now according to the problem explanation on Microsoft Docs, and your example which you don't have the source code for the assemblies you have to:
Add a reference to 'Assembly_YY' version 65535.65535.65535.65535 of the DLL to your application to make it compile and to enable the application to run, you can provide an application configuration file that includes a <dependentAssembly> element that uses <assemblyIdentity> and <codeBase> child elements to specify the location of version 12.3.0.0 of the DLL.
You are referencing a higher version of DLL then the one you currently have.
You will need to add the reference to the higher version assembly:
'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=c878e80841e75d00'
in order to solve this.
Right now you are referencing
'Assembly_X' with identity 'Assembly_X, Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d0
If this is a downloadable library, search for it in the nuget package manager and download it.
If it's a library written by you, obtain the latest version of the library and add it to your project.
We have an app A that has a reference to an assembly B that contains some static methods. Assembly B is in the same Visual Studio solution as app A.
We want the users of our app A to be able to write plugins. They build the plugin (at present) by creating a new Class Library solution in Visual Studio, getting the Nuget Package for app A, and adding a reference in their plugin solution to assembly B, so that the plugin code compiles.
They do not need to test their plugin, which is why the code just needs to compile, although it would be nice if they could debug their code when running it in app A.
Once their code has compiled, the DLL for the plugin is put in a share and given to a different team (bureaucracy I know) who put it with the rest of app A's DLLs.
I would like the plugin DLL to use the assembly B DLL that is with all of app A's DLLs.
When I run app A, the Activator class picks up the plugin DLL and correctly creates an instance, but as soon as one of the static methods from assembly B is called, the plugin throws a MissingMethodException.
Things I have tried:
The plugin solution definitely works fine if you create it and compile it within application A's Visual Studio solution.
App A uses framework .Net 4.5, assembly B uses framework .Net 4.0, I have tried building the plugin with both frameworks without success.
The "Specific Version" of the reference to assembly B in the plugin solution was false in all cases tested.
I would welcome immediate solutions to this problem but also broader architectural suggestions on how to get these plugins to work. I apologise if there is a duplicate question of this, I couldn't find one.
For starters you can use "Dotpeek" to decompile dll and see if the method defination exactly matches.
It's a free software available to decompile dotnet libraries.
If you don't have access to .pdb file then i would recommend using "dotnet reflector",or "IL Spy" it will decompile without pdb files.
Also do make sure you are referencing project in visual studio not the output dll.
I managed to fix my problem as follows:
Although the plugin only directly used static methods in Assembly B, these static methods actually made a chain of calls to various OTHER assemblies.
Instead of just adding a reference to Assembly B in my plugin, I did a Nuget command:
Install-Package -Id AppA -ProjectName Plugin
And this downloaded the latest AppA to the packages folder and added a reference to EVERY dll of AppA.
Like before, it compiled, but this time when I dragged the plugin dll into the AppA bin folder, the plugin code ran without throwing an exception.
This is probably a dumb question but I can't for the life of me figure it out. I'm trying to use the a Tesseract C# wrapper (https://github.com/charlesw/tesseract) and I've got it all working except for one error that reads
Error 11 The type 'System.Drawing.Bitmap' is defined in an assembly
that is not referenced. You must add a reference to assembly
'System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'.
My first thought was "oh, let me just add an assembly reference to System.Drawing". Except there isn't one. When I right click References in the Solution Explorer -> Add Reference -> Assemblies -> Framework there is no System.Drawing. I did find System.Drawing.dll under COM, but it won't let me add it, saying
The ActiveX type Library [path] was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead.
Typing "using System.Drawing" at the top of my program does not cause an error, but it also does not solve the problem.
Any help is appreciated.
Edit: Am I in the right place?
You won't go far with this project, there's this dependency for System.Drawing and the whole project doesn't seem like it's targeted towards Xamarin.
As written here Xamarin Tesseract OCR binding for Android there are bindings for Xamarin.iOS, and the person is asking for bindings for Xamarin.Android. There's indeed a version of tesseract for Android here https://github.com/rmtheis/tess-two and apparently the response is to create a binding to this Java Android version.
Both projects, the binding for Xamarin.iOS as well as Xamarin.Android are bindings to platform specific bindings who both wrap the native C++ library. Probably the best solution would be to completely bypass the Java and Objective-C wrapper by create a specific P/Invoke wrapper for C#using SWIG.