PROBLEM
I created a C# project that implements the System.Management.Automation reference (allowing me to write powershell commands in my project).
I compiled the project and copied the dll to the plugins folder of my Rainmeter application so that I could leverage it along with the other dll 's Rainmeter comes with.
This works perfectly on my machine (64 bit); however, I want to load this same configuration on another server (also 64 bit). Both machines are using the same installation of the .NET framework (4.5).
According to this source, I should be able to simply copy the Rainmeter folder with the included dll and it should run without any problems (I'm using the portable installation of Rainmeter).
I receive the error "System.IO.FileNotFoundException" unless I remove the "SystemVersion.dll" that I created, when running Rainmeter on another server.
QUESTION
Since the issue is clearly the dll I have added, I'm assuming the reference is not being added to the dll?
=========================================================================
EDIT
As per #Hackerman 's answer, the issue was that the dll was unable to find my reference. The path for System.Management.Automation required powershell version 3.0 to be installed on the machine in order to load the reference.
My server was running powershell version 2.0, but after installing version 3.0 the dll was able to load the reference and Rainmeter would display my results as expected.
When you build your class library, the references don't get embedded on your final dll. The System.IO.FileNotFoundException that you are getting is because your dll can't load the System.Management.Automation.dll reference on the destination server. Installing PowerShell 3.0 on the server should resolve the issue.
Related
I'm working on a .net core web app (targeting net461).
The app needs to reference a COM dll.
I added the COM reference and the app still builds on my dev machine.
However, on the build server it fails to build with this error:
C:\Program Files (x86)\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(2604,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveComReference" task could not be loaded from the assembly Microsoft.Build.Tasks.Core
After searching a bit, it seems like it's a pretty uncommon error.
Anyone know what the error is and/or how to fix it?
UPDATE: Seems like the dotnet CLI does not support COM references. Visual Studio uses msbuild directly behind the scenes, but on the build server, I was using the dotnet CLI commands.
WORKAROUND:
Reference the COM dll and rebuild. Visual Studio will generate an interop
dll. It will be named something like Interop.MyComDLL.dll. It is found in the build output directory.
Copy the generated Interop dll to somewhere in the application (I just
used a /dlls folder at the root application level).
Remove the COM dll reference.
Add a direct reference (Dependencies > Add Reference... > Browse in Visual Studio) to the Interop dll
It should also fail on developer machine if you try to build it using the same command as on build server, e.g.
dotnet.exe build Solution.sln --configuration Release --no-incremental
VS building solution using msbuild, it's a different way.
My suggestion would be to do any COM interop using dynamics, if you want to make it easier to change in the future, create an interface that that has all the COM properties and methods you need to access.
Create a class, implementing the interface, that creates the COM Object dynamically as part of the constructor. Then implement each of the methods and properties to access the the dynamic object you created.
This should remove any build time dependency, give an interface the rest of your code can depend on, and give an easy way out of the COM at a later date if required.
You might also find Rick Strahl's article for COM in .Net Core useful?
https://weblog.west-wind.com/posts/2019/Jan/22/COM-Object-Access-and-dynamic-in-NET-Core-2x
Hope this helps :)
After searching and applying all solutions for below problem, are not working.
What I have done-
1. I created a .dll in C#, made its com visible ture.
2. I creadted the .tlb using regasm.
3. Created a Delphi 7 project where I imported this type library (.tlb) and calling the function of this dll.
4. All is running fine on my PC.
Now when I copied these all files (including .dll, even .dcu too) to another PC (.Net framework 4.5 installed) and tried to run the .exe, it gives me error "Class not registered", when I tried registering it with RegSvr32 then it shows error -"Entry point not found".
What else am I missing? Is there any other prerequisite to run Delphi 7 exe with dll on another PC?
To register a .net assembly you must use regasm and not regsvr32.
Making the entire assembly COM visible is probably a mistake. Do you really want to make all public type COM visible? It would be more usual to apply the ComVisible attribute to specific types.
You don't need to copy dcu files. These are used as intermediate files for the Delphi compiler. Assuming you aren't using runtime packages, just the executable, and the registered assembly should suffice.
I've made a project with c# in which I use "Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll" as a reference assembly.
When I install my program on another computer it gives me an error message:
unable to run the application requires that assembly
microsoft.data.schema.sql.unittesting version 12.0.0.0 in the global
assembly cache
How can I install this .dll in GAC using code.
This assembly is used for unit testing databases. It's shouldn't be needed by your production code.
Remove it from your project references and try if the solution still builds and, if so, the program still works on both your machine as well as on another machine.
I am new to ServiceStack. I am testing out the MovieREST example. When I run the project, the Immediate Window shows me this error
"A first chance exception of type 'System.DllNotFoundException' occurred in Mono.Data.Sqlite.DLL"
and no movie list is loading up. So, there is only a blank "Add a new movie" page with some default inputs, everytime I hit Add new movie, the DllNotFoundException will be thrown.
Do I need to install any dependency projects to make it work? I am running it with VS2010, IIS, and Vista 32bit (yup..I know..). Also installed Mono and sqlite 32bit just now blindly, I am not even sure if the project needs them to run. From the code, I can see it is referring to "App_Data/db.sqlite" and References already has sqlite3.dll, I replaced the dll with the 32bit one I download anyway, but still no luck.
Please give me some hints on what I am missing? Thank you.
The Mono.Data.Sqlite.DLL is just a managed wrapper that needs to find the unmanaged sqlite3.dll in order to run (which is what holds the native binary of Sqlite itself).
It looks for this in the /bin directory, to have it deployed there whenever you build you need to copy sqlite3.dll to your project root / and set the Build Action to Content and change the Copy action to Copy if newer.
Ideally you'd want to use the right sqlite3.dll for your architecture (the ServiceStack.OrmLite.Sqlite.Mono NuGet package contains both 32bit / 64bit dlls) although IIS/.NET can work with 32bit unmanaged dlls but will require some tweaking explained here.
Using mixed-mode assemblies
Whilst Mono.Data.Sqlite.DLL lets you run the same .NET app on Mono, if you only want to run Sqlite in Windows you can also use the mixed-mode assemblies that have the unmanaged native sqlite library embedded in the .NET dll. There are 2 different versions available on NuGet:
ServiceStack.OrmLite.Sqlite32
ServiceStack.OrmLite.Sqlite64
Remove any references to existing OrmLite or Sqlite dlls as both of these NuGet packages contain all the Sqlite + OrmLite dlls needed.
I have the following solution:
MySolution
-Project: MyServer (WPF)
-Project: MyClient (WPF)
-Project: MyLibrary (Class library)
Inside MyLibrary, I reference an external DLL System.Data.SQLite for SQLite access. I set the dll to Copy to local so that when I build, it will copy the dll into the directory where the class library MyLibrary will be built into a dll.
In the other two projects (MyClient and MyServer) I reference the class library project so I can have access to my shared routines but also have access to the SQLite libraries. This works great on the dev machine, but when I copy the Release folder to another machine, the Client/server apps refuse to run throwing an error that it can't find the SQLite dll.
What am I doing wrong here ?
Regards
Check that you have a sqlite.dll in your release folder. You can install i using nuget with the Package Management Console command "Install-Package System.Data.Sqlite".
If you then get a "BadImageFormat" exception, make sure you are using the correct version of sqlite for your system. It comes in 32 and 64-bit flavors.