I have created a NuGet package from .NET4.0 DLLs which include mixed (Managed and native) code.
The Native code is packaged up inside the .NET4.0 DLL but has a dependency on the Visual C++ 2013 Redistributable
I'm trying to brainstorm ways to either package the redist with the NuGet package and/or warn the user that they need it, but I'm drawing a blank.
Anyone got any ideas?
I actually kind'of solved this myself. While I couldn't find a solution to include the VCpp Runtime as a dependency to a NuGet package, I did find a solution to warn the user that the Visual C++ 2013 Runtime was needed.
I run this code once, statically, at startup of the component/library that requires the VC++ Runtime:
private static void AssertVcppDependencies()
{
var system32Path = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
var system64Path = Environment.GetFolderPath(Environment.SpecialFolder.System);
string platform = Environment.Is64BitProcess ? "x64 and x86" : "x86";
bool success = File.Exists(Path.Combine(system32Path, MSVCP120DllName));
if (Environment.Is64BitProcess)
{
success &= File.Exists(Path.Combine(system64Path, MSVCP120DllName));
}
if (!success)
{
throw new InvalidOperationException("This Application Requires the Visual C++ 2013 " + platform +
" Runtime to be installed on this computer. Please download and install it from https://www.microsoft.com/en-GB/download/details.aspx?id=40784");
}
}
This should alert any developers that are consuming your NuGet package that they need to install the runtime.
Related
I have a .NETCore app which I am trying to add 7 zip functionality to.
Compiling gives this warning:
warning NU1701: Package 'SevenZipSharp 0.64.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
So I presume the project is .NETCore v5.0. Can I run SevenZipSharp in this project?
Running the app gives an error at the call to CompressFiles: SevenZip.SevenZipLibraryException: 'Can not load 7-zip library or internal COM error! Message: failed to load library.'
public void ZipQOB(string sevenZipDllPath, string zippedQobPath, string unzippedQobFiles)//List<string> sourceFiles)
{
// throw exception if paths passed in are null, does 7zipsharp throw exceptions in this case?
try
{
if (System.IO.File.Exists(sevenZipDllPath) && System.IO.Directory.Exists(zippedQobPath))// && System.IO.Directory.Exists(unzippedQOBFiles))
{
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll");
//SevenZipCompressor.SetLibraryPath(sevenZipDllPath);
SevenZipCompressor.SetLibraryPath(path);
SevenZipCompressor sevenZipCompressor = new()
{
CompressionLevel = SevenZip.CompressionLevel.Ultra,
CompressionMethod = CompressionMethod.Lzma
};
string[] files = System.IO.Directory.GetFiles(unzippedQobFiles);
sevenZipCompressor.CompressFiles(zippedQobPath + #"\zip.QOB", files);
//System.IO.Path.ChangeExtension(zippedQobPath, ".QOB");
}
This question How do I use 7zip in a .NET Core app running on Linux? mentions a CLI wrapper ported from .NET Framework to .NET Core, but I can't find any details - is this something I would have to write and how?
I have already tried things suggested elsewhere, I altered the project build setting to:
Platform Target = AnyCPU,
ticked Prefer 32-bit
Should I just look at a different option as this page seems lists some stating .netcore compatible: https://github.com/topics/7zip?l=c%23
Many thanks for any help :)
I created a new console project and used NuGet to add CefSharp.Common and CefSharp.OffScreen.
I added the following code:
static void Main(string[] args)
{
try
{
ChromiumWebBrowser Chromium = new ChromiumWebBrowser("www.google.com");
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine(ex.Message);
}
Console.WriteLine("Test Complete Press Enter to Close Window");
Console.ReadLine();
}
I then published the project and attempted run it and I received this error: System.IO.FileLoadException: A procedure imported by 'CefSharp.Core.Runtime.dll' could not be loaded.
The following files are in the published folder
CefSharp_Test.exe
CefSharp_Test.exe.config.deploy
CefSharp_Test.exe.deploy
CefSharp_Test.exe.manifest
CefSharp.Core.dll.deploy
CefSharp.Core.Runtime.dll.deploy
CefSharp.dll.deploy
CefSharp.Offscreen.dll.deploy
I saw that CefSharp recently pushed a change that created the CefSharp.Core.Runtime.dll - https://github.com/cefsharp/CefSharp/issues/3319 and I assume the issue is in some way related to CefSharp determining if the x86 or x64 Runtime.dll should be used but I have been unable to find a way to resolve the issue.
The project does run without issues from Visual Studio.
Edit - From the CefSharp readme it appears that libcef.dll, icudtl.dat, CefSharp.BrowserSubprocess.exe, and CefSharp.BrowserSubprocess.Core.dll are required dependencies. I have added those files to the project, set to copy always, and re-published. The error now reads System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.Core.Runtime.dll' or one of its dependencies. The specified module could not be found.
Edit - It appears that this is a known issue and will be fixed in a future release of CefSharp. https://github.com/cefsharp/CeSharp/pull/3391
Edit - I attempted to run it using the CefSharp v88.2.40-pre and received the same error.
Edit - CefSharp v88.2.40 has been released. I have attempted to run with that and received the same error.
I encountered the same error while doing cefsharp updates today.I deleted cef.redist.x64, cef.redist.x86, CefSharp.Common and CefSharp.WinForms plugins.Then I reinstalled the CefSharp.WinForms plugin from the nuget package manager window.
Gave the same error again.Then I looked at the plugins versions.There were differences between cef.redist.x64, cef.redist.x86 versions and CefSharp.Common, CefSharp.WinForms versions.Because NuGet Package Manager, installed the stable version of the CefSharp.Common and CefSharp.WinForms plugins.
I deleted the plugins again and again.I checked the package sources.I even tried alternatives.Finally, I tried to install the plugins via the package manager console.I installed the following plugins respectively.
Install-Package cef.redist.x86
Install-Package cef.redist.x64
Install-Package CefSharp.Common
Install-Package CefSharp.WinForms
cef.redist.x86 and cef.redist.x64 extensions were installed without any problems.When it came to installing the CefSharp.Common extension, I got an error again.Because, console was trying to install the stable version.
I selected the latest version of CefSharp.Common and CefSharp.WinForms plugins from the nuget package manager window and installed them.And finally I was able to run my project with no errors.
Note: I did this for winform.If there is a difference between versions like mine, you should try it. :)
I wrote a simple UWP app using the ML.NET framework, and it worked on one of my machines without installing any Nuget packages, without any additional setup etc.
However, on my other machine, after running the application, I get this error:
System.Runtime.InteropServices.COMException: 'Unspecified error
No suitable kernel definition found for op Sub (node Minus675)'
The error happens in this segment of code:
public static async Task<modelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
{
modelModel learningModel = new modelModel();
learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
learningModel.session = new LearningModelSession(learningModel.model); // it breaks here
learningModel.binding = new LearningModelBinding(learningModel.session);
return learningModel;
}
In case anyone should ask - yes I have added my .onnx model in the Assets folder. My configuration is: VS 2017, Windows 10 version 1809, build 17763.194, and I have Windows 10 SDK version 10.0.17763.132. I have tried installing the Visual Studio Tools for AI and ML.NET Templates VS extensions, but it didn't help.
Using nuget in Visual Studio 2013, I installed Ghostscript.NET into my project on my Windows x64 PC.
Just to make sure I wasn't crazy, I checked it:
PM> Install-Package Ghostscript.NET
'Ghostscript.NET 1.2.0' already installed.
Project already has a reference to 'Ghostscript.NET 1.2.0'.
PM>
The project is used by multiple developers. It targets Any CPU, and needs to remain that way.
Here is my code:
public static void GhostscriptNetProcess(String fileName, String outputPath)
{
var version = GhostscriptVersionInfo.GetLastInstalledVersion();
var source = (fileName.IndexOf(' ') == -1) ? fileName : String.Format("\"{0}\"", fileName);
var output_file = (outputPath.IndexOf(' ') == -1) ? outputPath : String.Format("\"{0}\"", outputPath);
var gsArgs = new List<String>();
gsArgs.Add("-q");
gsArgs.Add("-dNOPAUSE");
gsArgs.Add("-dNOPROMPT");
gsArgs.Add("-sDEVICE=pdfwrite");
gsArgs.Add(String.Format(#"-sOutputFile={0}", output_file));
gsArgs.Add("-f");
gsArgs.Add(source);
var processor = new GhostscriptProcessor(version, false);
processor.Process(gsArgs.ToArray());
}
Whenever I attempt to debug the application, I get the following error message:
GhostscriptLibraryNotInstalledException was unhandled
An unhandled exception of type 'Ghostscript.NET.GhostscriptLibraryNotInstalledException' occurred in Ghostscript.NET.dll
Additional information: This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html
Looking up the Ghostscript.NET.GhostscriptLibraryNotInstalledException did not provide any useful information, though this post on CodeProject indicated that the debugger is running in 32-bit mode whereas I have the 64-bit version installed.
That's all well and good know, but how do I go about testing the new code I wrote that uses Ghostscript?
If you are testing with MS Test you have to set the processor architecture in which the tests are run, because Ghostscript.Net verifies the process architecture (Environment.Is64BitProcess) to search for the ghostscript installation in the registry.
In Menu > Test > Test Settings > Default Processor Architecture > X64.
Have you actually installed Ghostscript ?
Ghostscript.NET is merely a .NET interface to Ghostscript, it looks to me like the message:
"This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html"
is trying to tell you that you don;t have a 32-bit version of Ghostscript installed. It even tells you where to go to download a copy.
So have you installed Ghostscript ? Have you installed the 32-bit version of Ghostscript ?
I'm currently trying to consume a FORTRAN DLL that I have been given by a third party. Now, it has been consumed before by other vendors (unsure whether they used C# or not to consume it), but I'm getting some reference errors when I'm trying to consume it.
I'm basically trying to get it to work within a small test app.
Here's the C# code I'm using to import (basic COM really):
[DllImport("foo.dll")]
public static extern void foo(ref int IS, ref double[] BETA, ref int K, out double TH, out double SETH, out int IER);
static void Main(string[] args)
{
double[] betas = new double[3];
betas[0] = 25.6;
betas[1] = 30.8;
betas[2] = 35.8;
int score = 5;
int numberOfItems = 3;
double latentVariable;
double standardErrorOfEstimate;
int errorCode;
foo(ref score, ref betas, ref numberOfItems, out latentVariable, out standardErrorOfEstimate, out errorCode);
Console.ReadLine();
}
Note: The DLL method signature matches that what I have.
When trying to run the application, I get the following Exception:
Unable to load DLL 'foo.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)
Looking in the event log, the following details is shown on the error:
Activation context generation failed for "C:\dllpath\foo.dll". Dependent Assembly Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found. Please use sxstrace.exe for detailed diagnosis.
Also, running sxstrace, the same information and error is shown:
ERROR: Cannot resolve reference Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8".
ERROR: Activation Context generation failed.
End Activation Context Generation.
Now, after doing some googling and looking round on here, some people recommend installing the Redistributable packages for C++. I've done that for both 2008 and 2010 on both x86 and x64 platforms and still no joy.
Anyone got any ideas? I'm using Visual Studio 2010 and Windows 7 (if that helps?).
The problem is DebugCRT. You've got the debug build of that DLL and it has a dependency on the debug build of the CRT. Which requires an appropriate version of Visual Studio, the only way to get the debug build of the CRT on your machine. Which is Visual Studio 2008, indicated by the 9.0 version number. You have no use for the debug build if you don't also have the source code for this DLL. Nor can you get this DLL deployed and working on your customer's machine.
Get ahead by contacting the owner and asking for the release build so that the redistributable packages can work.