Could not load type 'System.ServiceModel.Activation.VirtualPathExtension' - asp.net-core-3.1

I am using SAPNCo.dll Net Core 3.1.
I have not created instince RfcConfigParameters.
public RfcCongfigParameters GetParameters()
{
try
{
var instance=new RfcCongfigParameters();
foreach (KeyValuePair<string, string> p in _parameters)
{
instance.Add(p.Key, p.Value);
}
return instance;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
Could not load type 'System.ServiceModel.Activation.VirtualPathExtension' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Exception Detail Image
I tested Console .Net Core 3.1 Project.
thank u helping.

Related

protobuf-net causing Invalid wire type error during deserialization

Working on a POC of transitioning from BinaryFormater to Protobuf for Serialization and deserialization inorder to reduce the deserialization time. While trying to deserialize using the protobuf library I get the following error "Invalid wire-type; this usually means you have over-written a file without truncating or setting the length" while deserializing a file in a rest web API project but the same code runs fine in another web job project with same .Net version.
protobuf-net Version: 3.1.26
.NET version: .NET framework 4.6.2
Seems to be maybe an internal package dependency version issue or issue if the deserialization happens in a w3 process.
Has anyone faced such issues with the protobuf-net package for a REST service.
Below is the code where the ProtoDeserialize function throws a exception Serializer.Deserialize<T>(stream) is called
[ProtoContract]
public class Temp
{
[ProtoMember(1)]
public string name;
[ProtoMember(2)]
public int no;
}
[HttpGet]
public HttpResponseMessage DerserializeProtoBuf()
{
try
{
var x1 = new Temp();
x1.name = "testData";
x1.no = 10;
var data1 = ProtoSerialize<Temp>(x1);
var y = ProtoDeserialize<Temp>(data1); // throws exception
}
catch
{
}
}
public static T ProtoDeserialize<T>(byte[] data) where T : class
{
if (null == data) return null;
try
{
using (var stream = new MemoryStream(data))
{
using (var decompressor = new GZipStream(stream, CompressionMode.Decompress))
{
return Serializer.Deserialize<T>(stream); // throws Invalid wire-type error here
}
}
}
catch(Exception ex)
{
throw new InvalidDataException(String.Format("Invalid data format when proto deserializing {0}", typeof(T).Name), ex);
}
}
public static byte[] ProtoSerialize<T>(T record) where T : class
{
if (null == record) return null;
try
{
using (var stream = new MemoryStream())
{
using (var gZipStream = new GZipStream(stream, CompressionMode.Compress))
{
Serializer.Serialize(gZipStream, record);
}
return stream.ToArray();
}
}
catch(Exception ex)
{
throw new InvalidDataException(String.Format("Invalid data format when proto serializing {0}", typeof(T).Name), ex);
}
}
I have tried adding the package dependencies versions explicilty by adding bindingRedirects.
Have tried updating and degrading the version of protobuf to 2.3.7 and other before versions
Pass decompressor instead of stream to Deserialize. You're passing it the compressed gzip data instead of the decompressed protobuf payload.

Access environmental variables in dozer mapping

I want to access my environment variables in dozer mapping file. It there a way? I looked the official documentation and they listed usage of variables. But they are not the environmental variable. Also is there a way to access the .property file values in dozer mapping file?
The easiest way would be to use a class factory and create a new instance of the class and pass in the needed environment variables. See the documentation. http://dozer.sourceforge.net/documentation/custombeanfactories.html
public class EnvironmentSetterBeanFactory implements BeanFactory {
public Object createBean(Object source, Class<?> sourceClass, String targetBeanId) {
try {
Class<?> targetClass;
targetClass = Class.forName(targetBeanId);
Object instance = targetClass.newInstance()
if (instance instanceof YourClass) {
YourClass yourClass = (YourClass) idSource;
yourClass.setThatVar(System.getenv("myenvvar"));
}
return instance;
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

GWT+JPA Persistence.Exception source code not found

I'm trying to create a simple DB connection using JPA.
It works fine but when I try to Throw an Exception to the client I get the error:
[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?
[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
I get no error in development mode and it compiles fine, but when the app module is loaded there is where I get the error.
I have the required imports in server/Composer and client/Presenter classes
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
I also added the following jars to the classpath and build path:
javax.persistence.jar
jpa-annotations-source.jar (http://code.google.com/p/google-web-toolkit/issues/detail?id=1830#c14)
I also tried adding to gwt.xml
<source path='client'/>
<source path='shared'/>
<source path='server'/>
Any ideas on how to tell eclipse where to find the source code??
Thanks
Here is the code:
//Create composer from Composer.class in server
public static Composer createComposer(String name)
throws EntityExistsException {
Composer comp = new Composer();
comp.setName(name);
comp.setId(1);
EntityManager entityManager = entityManager();
entityManager.getTransaction().begin();
entityManager.persist(comp);
entityManager.getTransaction().commit();
entityManager.close();
return comp;
}
///fire Request from createComposer(above) in Presenter.class
req.fire(new Receiver<ComposerProxy>() {
public void onSuccess(ComposerProxy arg0) {
ComposerProxy comp;
comp = arg0;
}
public void onFailure(Throwable caught)
throws Throwable {
// Convenient way to find out which exception
// was thrown.
try {
throw caught;
} catch (EntityExistsException e) {
} catch (EntityNotFoundException e) {
}
}});
}});
[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?
[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
You can't use types such as EntityExistsException or EntityNotFoundException in client-side GWT code at all.
These are plain Java classes and GWT don't know how to translate them to JavaScript.
You can only use very limited part of external libraries in your client-side code. These libraries (like Visualisation for example) are designed and prepared specifically for client-side and require inheriting their GWT module in your application's module.
I think that what you really want to do is something like that:
public void onFailure(ServerFailure failure) throws Throwable {
if(failure.getExceptionType().equals("javax.persistence.EntityExistsException")){
...
}else if(failure.getExceptionType().equals("javax.persistence.EntityNotFoundException")){
...
}
}
Because you can read type of server-side exception as String, see Javadoc for Receiver and ServerFailure.
Thanks Piotr for your help.
Here is the code for what I finally did:
Code in the client
req.fire(new Receiver<ComposerProxy>() {
public void onSuccess(ComposerProxy arg0) {
ComposerProxy comp;
comp = arg0;
}
public void onFailure(ServerFailure failure) {
serverError.getServerError(failure,
"onAddButtonClicked");
}
});
I created a class to handle the errors
public class ServerError {
public ServerError() {
}
public void getServerError(ServerFailure failure, String message) {
// Duplicate Key Error
if (failure.getMessage().contains(
"IntegrityConstraintViolationException")) {
Window.alert("Duplicate Key " + message);
return;
}
// Connection Error
if (failure.getMessage().contains("NonTransientConnectionException")) {
Window.alert("Connection error ");
return;
}
// TimeOut Error
if (failure.getMessage().contains("TimeoutException")) {
Window.alert("Timeout Error" + message);
return;
}
// Other Error
else {
Window.alert("Duplicate Key " + message);
return;
}
}
}
Service in the server
public static Composer createComposer(String name) throws Throwable {
EntityManager entityManager = entityManager();
Composer comp = new Composer();
try {
comp.setName(name);
comp.setId(1);
entityManager.getTransaction().begin();
entityManager.persist(comp);
entityManager.getTransaction().commit();
} catch (Exception e) {
log.error("Error in Composer::createComposer( " + name + ") //"
+ e.toString());
throw e;
} finally {
entityManager.close();
}
return comp;
}
One problem I found is that the variable 'ServerFailure failure'only contains info in the failure.message; all the other variables are null.

JPA #OneToMany not persisting/cascading

I have the following code in UserController in my Session Scoped Bean
public void addItemToBundle(ItemEntity item){
//System.out.println(item.getTitle());
try {
em.getTransaction().begin();
UserEntity user = em.find(UserEntity.class, this.username);
BundleEntity bundle = new BundleEntity();
BundleEntityPK compositePk = new BundleEntityPK();
compositePk.setCheckedOutDate(new Date());
compositePk.setItemId(item.getItemId());
compositePk.setUsername(user.getUsername());
bundle.setId(compositePk);
Set<BundleEntity> bundles = new HashSet<BundleEntity>();
bundles.add(bundle);
user.setBundleEntities(bundles);
em.persist(user);
em.flush();
em.getTransaction().commit();
} finally {
}
}
public String addToBundle(){
try {
addItemToBundle(item);
} catch (NullPointerException e) {
e.getMessage();
}
return null;
}
This code uses private ItemEntity item; which gets passed in by the following JSF markup:
<p:commandLink action="#{itemController.item}">
<f:setPropertyActionListener target="#{itemController.selectedItem}" value="#{movie}" />
</p:commandLink>
(I'm using PrimeFaces in this example) The problem is that the addItemToBundle is not calling any SQL code in the console (I have FINE enabled) and the bundle never gets created or added to the user. I also tried em.persist(user) and em.flush() and setting cascadeType in my UserEntity with no luck.
#OneToMany(mappedBy="userEntity",cascade=CascadeType.PERSIST)
private Set<BundleEntity> bundleEntities;
Thanks!
You know that this:
try {
addItemToBundle(item);
} catch (NullPointerException e) {
e.getMessage();
}
is very bad practice, right? Maybe, that's the problem here, you run into a NPE and never notice it.
You should at least log the exception to know what's going on there (just for demo purposes, I've used stdout, please replace with your favorite logging framework):
try {
addItemToBundle(item);
} catch (NullPointerException e) {
System.err.println(e.getMessage()); //use logger here
}

A network related error or instance-specific error occured while establishing a connection to sql server

This is the error which arises when I tried to debug an application under Visual C# 2010
I write that code to retrieve some rows from a database table, I already attached the two well known databases Pubs and Northwind to the db explorer, but the error remains
class Author
{
SqlConnection _pubConnection;
string _connString;
public Author()
{
_connString = "Data Source=./INSTANCE2;Initial Catalog=pubs;Integrated Security=True";
_pubConnection = new SqlConnection();
_pubConnection.ConnectionString = _connString;
}
public int CountAuthors()
{
try
{
SqlCommand pubCommand = new SqlCommand();
pubCommand.Connection = _pubConnection;
pubCommand.CommandText = "Select Count(au_id) from authors";
_pubConnection.Open();
return (int)pubCommand.ExecuteScalar();
}
catch (SqlException ex)
{
throw ex;
}
finally
{
if (_pubConnection != null)
{
_pubConnection.Close();
}
}
}
}
static void Main(string[] args)
{
try
{
Author author = new Author();
Console.WriteLine(author.CountAuthors());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
the Connection string isn't ok , i correct it and it works fine