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)
Related
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
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.
Hi I have console application which is written in VB.NET. For this I added c# class library with existing solution. I wrote code in c# class library. Now when I try to run, it is going to VB.NET console application by default. I am not able to run my c# class library.
For clear understanding lets call VB.NET project as classVB and class library as classC#
I tired these methods to make it work :
1) Added classC# reference to my classVB project and made classVB as startup project. I used using statement also to refer to my classVB project as Using classVB. And I put break point in my classC#.But still it is pointing to classVB project
2) Tried to made classC# as startup project( Even I knew this doesn't gonna work). For this I am getting usual error which says "A project with an output Type of class library cannot be started directly."
3) Right click on solution and start up project option -> Single startup project and selected classVB.
But none of this is working. It is always pointing to my classVB project even after I put breakpoint on c#class library code.
Its the first time I am working on library class, so any help on this would be appreciated.
You can't directly run a class library. It is not executable. You can reference the code from it in your VB project, but a class library can never run by itself. To access a public method in your class library from VB, refer to it by Namespace.ClassName.MethodName.
Change the compilation output of the library to the same path where you added the reference in the VB.NET application. Generate the library and check the build is successful.
Do not forget to change the library class to configuration debug in the solution to generate the PDB file that will allow you debugging. Put a breakpoint and try again.
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.
I have a C# console application in Visual Studio 2010. It has a Main() method as well as a bunch of utility classes. I'd like those utility classes to be available to other solutions. From reading online it seems that I need to compile it as a Class Library (DLL). So here's what I did:
Went in Visual Studio to "Project > [ProjectName] Properties > Application" and changed "Output type" from "Console Application" to "Class Library"
Rebuilt; ProjectName.dll was created in bin/Debug.
Created a new Console Application
Solution Explorer > Add Reference > browse to ProjectName.DLL, select it.
However, neither IntelliSense nor the Object Browser could find the classes inside that DLL.
I tried recompiling several different Console Applications as Class Libraries and got the same result. I also noticed that it works if I initially create the solution as a Class Library, but not if I convert it to one later.
Any tips?
You do not need to build it as a dll. VS 2010 (and IIRC 2008) allow referencing exe assemblies. All you need is for they relevant types to be declared public - top-level classes defualt to internal if you don't add a specifier.
You can switch output type to Class library in project properties as well - then you will have an output as dll instead exe file
What I've always done (since this is what you do with C++ static libraries, which is what I normally use - though I think it has some advantages for C# too) is add the class library's project to the solution, then add a reference to it in the project (or projects) that uses it.
When you go to add a reference, the list of potential references includes items from the solution, so it should be fairly obvious what to do. You should then get intellisense for your library.
One advantage of doing things this way is that if you need to edit files in the library project, it's very straightforward because they are close to hand, and the project then gets rebuilt automatically when you compile the solution.
Make sure that the classes in your dll project are public.
At first, from the point of view of managed libraries it does not matter what kind of Output type is your managed library. I mean that you can successfully reference ConsoleApplication1.exe from ConsoleApplication2.exe project (so you have no reason to convert ConsoleApplication1.exe to ConsoleApplication1.dll).
At second, I've tried to reproduce your situation, but... without effect. My VS displays types/methods from ConsoleApplication1.dll. One reason I can suppose is that you have forgotten to set visibility modifier (public keyword) for your utility classes.