docx4j.NET installation issue - docx4j

I've installed docx4j.NET 3.0.1 from Nuget with vs2012.
When I try to use the library with this call
WordprocessingMLPackage.load(inputS, "");
I receive this error:
System.TypeInitializationException:
The type initializer for 'org.docx4j.openpackaging.packages.OpcPackage' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'slf4j-api,
Version=1.7.6.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies
The version of slf4j-api in the docx4j.net 3.0.1 distribution is 1.7.5.0.
Is there a problem in the distribution of package?

Check that the list of referenced DLLs in your VS project includes slf4j-api. If not, add it.
If you have the DLL properly referenced, then as per the sample code in say https://github.com/plutext/docx4j.NET/blob/master/docx4j.NET/src/samples/c%23/Docx4NET/DocxToHTML.cs, you might need something like (note the bottom line):
// Programmatically configure Common Logging
// (alternatively, you could do it declaratively in app.config)
NameValueCollection commonLoggingproperties = new NameValueCollection();
commonLoggingproperties["showDateTime"] = "false";
commonLoggingproperties["level"] = "INFO";
LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties);
ILog log = LogManager.GetCurrentClassLogger();
log.Info("Hello from Common Logging" );
// Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.slf4j.impl.StaticLoggerBinder)));

Related

Setting up pythonnet for .net using NuGet

Iam trying to develop a simple calculator program embeddeding python in .net,I wanna reference pythonnet from NuGet to include it in my project
I installed pythonnet v2.3.0 using NuGet,I also have python 3 installed in my system
It would be nice if some one give me step by step instruction to embedd python net
form1.cs code :
using System;
...
using Python.Runtime;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
PythonEngine.Initialize();
}
private void button1_Click(object sender, EventArgs e)
{
int num1 = int.Parse(a.Text);
int num2 = int.Parse(b.Text);
result.Text = (num1 + num2).ToString();
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
}
}
}
}
When I use using(Py.GIL()) line in my code it compiler shows
System.BadImageFormatException: 'Could not load file or assembly
'Python.Runtime, Version=2.3.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. An attempt was made
to load a program with an incorrect format.'
This issue is likely caused by architecture (32-bit/64-bit) mismatch between Python.Runtime.dll and your Python.
pythonnet 2.3.0 NuGet packages currently published on nuget.org include two versions of the Python.Runtime.dll assembly: 32-bit(x86) and 64-bit(x64). There is a known issue with this package not installing the correct reference in the project, even if the project platform is set to 64-bit:
https://github.com/pythonnet/pythonnet/issues/472.
Usually the x86 reference gets installed, and if your Python is 64-bit, you get the above exception.
To fix this:
Remove the existing assembly reference from the project.
Manually add reference to the correct assembly from the installed nuget package (e.g. your_solution_dir\packages\pythonnet_py35_dotnet.2.3.0\lib\net40\x64\Python.Runtime.dll)
Changed the CPU architecture from AnyCPU to x64 and it fixed the issue.
I had same problem. I was running KerasExampleWinApp Sample (keras.net). The error was:
"...Python.Runtime, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies..."
To solve it, I just deleted the Nugget Reference and reinstalled it.

Can't compile ASP.NET 5 Web API when adding XML support

I'm trying to figure out how ASP.NET 5 Web API supports Content Negotiation. In order to support XML (in addition to the default JSON support), according to another answer here on Stack Overflow, I need to add that support from an optional NuGet package.
Things have changed a bit since that answer, but I pulled down the Microsoft.AspNet.Mvc.Xml package and edited my Startup.cs file:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc().AddMvcOptions(options =>
{
options.InputFormatters.Add(new XmlSerializerInputFormatter());
});
}
This, however, doesn't compile:
The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
Here are the full compilation error messages:
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,17,33,44): DNX 4.5.1 error CS0012: The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,45,33,78): DNX 4.5.1 error CS1503: Argument 1: cannot convert from 'Microsoft.AspNet.Mvc.Xml.XmlSerializerInputFormatter' to 'Microsoft.AspNet.Mvc.Formatters.IInputFormatter'
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,17,33,44): DNX Core 5.0 error CS0012: The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,45,33,78): DNX Core 5.0 error CS1503: Argument 1: cannot convert from 'Microsoft.AspNet.Mvc.Xml.XmlSerializerInputFormatter' to 'Microsoft.AspNet.Mvc.Formatters.IInputFormatter'
The error message seems fairly clear, but the project already includes Microsoft.AspNet.Mvc.Core, although not quite in the desired version:
Id Versions
-- --------
Microsoft.AspNet.IISPlatformHandler {1.0.0-rc1-final}
Microsoft.AspNet.Mvc {6.0.0-rc1-final}
Microsoft.AspNet.Mvc.Core {6.0.0-rc1-final}
Microsoft.AspNet.Mvc.Xml {6.0.0-beta5}
Microsoft.AspNet.Server.Kestrel {1.0.0-rc1-final}
Microsoft.AspNet.StaticFiles {1.0.0-rc1-final}
Microsoft.Extensions.Configurati... {1.0.0-rc1-final}
Microsoft.Extensions.Configurati... {1.0.0-rc1-final}
Microsoft.Extensions.Logging {1.0.0-rc1-final}
Microsoft.Extensions.Logging.Con... {1.0.0-rc1-final}
Microsoft.Extensions.Logging.Debug {1.0.0-rc1-final}
As I'm writing this, ASP.NET 5 is only available in a Release Candidate version, so the above packages are the most recent available.
Clearly, Microsoft.AspNet.Mvc.Core 6.0.0.0 isn't available. In a normal .NET project, I'd attempt to solve this issue with a binding redirect, but since this is ASP.NET 5, that's apparently no longer the way to do things.
How can I make my code compile?
I believe you have to use the Microsoft.AspNet.Mvc.Formatters.Xml package instead. Also see this issue on github.
Also a hot tip: Use http://packagesearch.azurewebsites.net/ to search for which NuGet-package contains the class you are looking for.

VB.NET desktop application error : Could not load file or assembly 'log4net, Version = 1.2.10.0 Culture = neutral, PublicKeyToken = 692fbea5521e1304'

I've setup a VB.NET desktop application in a Windows 8.1 pro 64-bit PC. After doing server configurations I'm trying to login to the application. It's when I'm getting the following error message:
Could not load file or assembly 'log4net, Version = 1.2.10.0 Culture = neutral, PublicKeyToken = 692fbea5521e1304'or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I've installed SAP Crystal Reports 13.0.3 64-bit yet it's still not working.
What is the reason behind this problem?
Check you Application files in Project Settings,find status of log4net dll whether included or not .Make it included in your project as below :
Problem solved.
The problem raised due to the mismatch in version of the log4net.dll file. My solution had log4net version = 1.2.9.0, while it needed the version = 1.2.10.0, hence the exception occured. I replaced the existing log4net.dll file with the one which has appropriate version and the problem was solved.

Upgrading App from .NET 3.5 to 4.0, COM fails now

I have an application that I am upgrading from the .NET 3.5 to the .NET 4.0 framework. It uses a COM library which is referenced. It works no problem in 3.5 but after converting to 4.0 I have issues getting the COM to work. The COM is from a 3rd party so we didn't develop it ourselves.
I get the following COM error (generic COM error, not specific to the COM object itself): hr = 0x8007000b
CLR gives me: 'The invocation of the constructor on type 'Skype_Business_Launcher.Main' that matches the specified binding constraints threw an exception.' Line number '3' and line position '5'.
And the C# logs:
=== Pre-bind state information ===
LOG: User = \phillip
LOG: DisplayName = Interop.SKYPE4COMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Skype Business Launcher, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file:
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///bin/Debug/Interop.SKYPE4COMLib.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
I removed the pathname for security reasons but I have checked all the path information and it's all correct. Also the COM library file exists where it's pointing to. It's also copied to the OBJ folder within the project as well.
Originally I was getting an error about the COM library not supporting embedded types so I made "Embed Interop Types" false (it was true below) and the error went away but I'm not sure if thats connected to this error or not so I thought I'd mention it just in case.
Again, it works just fine with 3.5.
Thanks,
A shot in the dark: it looks like you are using the x64 version of the framework. Was that already the case with 3.5 ? And is the COM server a DLL or an EXE ?
If the COM server is a DLL, there needs to be a "bitness" match between the DLL and your program.
when you convert your project to 4.0 the IDE can perform a issue to convert COM library into 4.0.
when you convert your project to 4.0 remove com library then Re include it in your project then i thing it should be works.

NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException

I have the following code set up in my Startup
IDictionary<string, string> properties = new Dictionary<string, string>();
properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", "Data Source=ZEUS;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;Password=xxxxxxxx");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), (IDictionary<string, string>) properties);
Assembly asm = Assembly.Load("Repository");
Castle.ActiveRecord.ActiveRecordStarter.Initialize(asm, source);
I am getting the following error:
failed: NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException : Unable to load type 'NNHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.
Possible causes are:
The NHibernate.Bytecode provider assembly was not deployed.
The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.
I have read and read I am referecning the All the assemblies listed and I am at a total loss as what to try next.
Castle.ActiveRecord.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
log4net.dll
NHibernate.dll
NHibernate.ByteCode.Castle.dll
Castle.Core.dll.
I am 100% sure the assembly is in the bin. Anyone have any ideas?
This problem occurs when NHibernate.ByteCode.Castle.dll was built with a different target platform as your project. To test this, change your program target platform from one or more of the following:
x64 to x86
x86 to x64
"Any CPU" to x86
"Any CPU" to x64
If any of those solve your problem, then you know that you just need to synchronize the DLL and your target platform.
I had this problem also, my solution was to add in the Assembly that creates session following code.
private NHibernate.ByteCode.Castle.ProxyFactoryFactory requiredButNeverUsed;