Permission denied: cannot call non-public or static methods remotely - c++-cli

in my code there are no "non-public" or "static" methods. All are public.I'm creating a Custom tool class, but However when I try to invoke a method from this class on the remote object I get stuck with an exception:
Permission denied: cannot call non-public or static methods remotely.
Fails at the following line everytime.
public ref class CustomTool : public Tool
{
public:
CustomTool():Tool()
{
}
};
CustomTool ^cs = gcnew CustomTool();
window->SetTool(cs); // here

Maybe the issue is with the method "SetTool" rather than the object "cs".
How does SetTool looks like?

Related

Asp Core 3.1 API JsonIgnore (not) ignored in deserialization

I have this setup
Asp Core 3.1 API
Shared Lib with MyClass that is sent between API and client
Client App with Com classes
On the MyClass that is sent between them I have a field ComField that references a com class, this is only used on the client app and should not be (de)serialized, therefore I have it marked with [JsonIgnore]
class MyClass{
[JsonIgnore]
public ComThingy ComField {
get{// code here that throws the error when deserilaized on the API}
set{// code here}
}
}
When I write the API to accept the class like this, I get an error when the class is deserialized. The debugger throws the error while deserializing the MyClass, before it enters the method:
[HttpPost]
public async Task<ActionResult<MyClassReply>> Post([FromBody] MyClass myclass){
// code here
}
The API throws an exception that accessing the getter on MyClass throws an error (because that Com stuff isn't on the API).
If I deserialize manually it works fine, but then my swagger doesn't generate the whole API correctly.
[HttpPost]
public async Task<ActionResult<MyClassReply>> Post(){
// this works fine
var rdr = new StreamReader(Request.Body);
var mcj = await rdr.ReadToEndAsync();
var myclass = Newtonsoft.Json.JsonConvert.DeserializeObject<MyClass>(mcj);
// code here
}
So my question is: how come the ASP API builtin deserialization ignores the JsonIgnore attribute and still tries to deal with that property (throwing an error), and why does deserializing manually work as expected (ie ignore that property)? The default pipeline still uses NewtonSoft rght?
And how do I make the default deserialization work correctly?
Starting from ASP.NET Core 3.0, the default JSON serializer is System.Text.Json, and not Newtonsoft.Json. You need to call .AddNewtonsoftJson() in your Startup.cs to use it (see for example this answer).
Your issue might simply be that you're not using the proper JsonIgnore attribute. Both serializers have the same named attribute:
System.Text.Json.Serialization.JsonIgnoreAttribute
Newtonsoft.Json.JsonIgnoreAttribute
Maybe your using statement are importing the Newtonsoft.Json one instead of the System.Text.Json one?

How to access the TelemetryClient singleton instance in startup for ASP.NET core app

I have an ASP.NET Core Web App that uses Application Insights for telemetry. I would like to wrap the TelemetryClient object with my own interface and add that instance to the services collection. To do this I need access to the singleton instance of Telemetry client in startup.cs. I can get the service information with this code:
var info = services.Where(x => x.ServiceType.Name == "TelemetryClient").Single();
That info has a ImplementationInstance that I would expect to find the instance in, but it is null. Is there any way to get the singleton instance of this item so I can create my wrapper class instance with it? My other option is to create the wrapper class in my controller constructors because there I can access it from the services container via this code:
HttpContext.RequestServices.GetService(typeof(T)) as T;
Any help would be appreciated. Thanks.
Couldn't you do this?
public class Wrapper
{
public Wrapper(TelemetryClient telemetryClient)
{
// Handle init
}
}
And register that in the service collection:
services.AddTransient<Wrapper>();
You can then get the Wrapper in your controllers through the constructor.
If this does not work for you, please leave a comment and explain why.

spring-boot property placeholder

I'm not able to figure out why I am not able to inject values into my application.properties file in spring-boot. external property into the logging.file variable. I have an application.properties file which looks like this
logging.file=${mylogfile}
server.port=${myport}
with corresponding Spring-boot Application class
#PropertySources({
#PropertySource("file:///c:/myfolder/externalprops.properties"),
})
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
and external property file
mylogfile=myoutput.log
myport=8060
When I run my spring-boot 1.0.2.REL application I get the following exception every time I try to inject mylogfile into the logging.file property in application.properties
Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'mylogfile' in string value "${mylogfile}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
Note that I am not having any problems injecting and starting up the application if I inject the server port number on its own.
I am going around in circles on this issue and cannot figure out what I am doing wrong.
I don't think you can use #PropertySource to inject values into "application.properties" - the latter has to be parsed and ready to use before any #Configuration is read, or even known about. Your external properties could go in "${user.dir}/application.properties" and I think that would achieve what you are trying to do.

Dozer DozerBeanMapper Instantiation Startup EJB App Server Glassfish

Dozer's documentation states that you should only have one instance of DozerBeanMapper running in the app on the server. For initial development I ignored this, now I want to update the app to do this.
How can I instantiate the DozerBeanMapper class when the application starts on glassfish, and how would I access its "map" method in another class once the application has started or been newly deployed?
This is for EJBs so I can't use any servlet to do this.
OK, so I've finally had time to refactor this code. With the pointer from #Mikko Maunu, I am editing my question to provide the code that I have working for me for anyone who might find it useful in the future.
package com.xyz.utilities.singleton;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.dozer.DozerBeanMapper;
#Startup
#Singleton
public class DozerInstantiator {
private DozerBeanMapper mapper = null;
#PostConstruct
void init() {
mapper = new DozerBeanMapper();
}
public DozerBeanMapper getMapper() {
return mapper;
}
}
And here is a straight forward usecase:
Inject an EJB member variable to your client class:
#EJB
DozerInstantiator di;
Within a method somewhere in the client class you can invoke the dozer mapper like so:
Credentials credentials = di.getMapper().map(credentialsDTO, Credentials.class);
// or
Credentials credentials = new Credentials();
di.getMapper().map(credentialsDTO, credentials);
If this is wrong or off base, someone please leave a comment. Until then, this seems to work so I'll use this solution I've developed with Mikko's input.
If you are using GlassFish 3.x, then you can use EJB 3.1 Singleton Session Bean:
#Startup //initialization in application startup
#Singleton //only one instance
public class DozerInitializer {
private String status;
#PostConstruct //executed once and only once when sole instance is created
void init {
//do steps needed to instantiate DozerBeanMapper
//here
}
}

When using Ninject in my MVC3 I get a Ninject.ActivationException: Error activating IRepository{Ranking} installed via Nuget

I installed Ninject via nuget, and I registered my binds in NinjectMVC3's RegisterServices method (created by nuget). Follow my code:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IUnitOfWork>().To<UnitOfWork>();
kernel.Bind<IRepository<Action>>().To<ActionRepository>();
kernel.Bind<IRepository<ActionType>>().To<ActionTypeRepository>();
kernel.Bind<IRepository<City>>().To<CityRepository>();
kernel.Bind<IRepository<Country>>().To<CountryRepository>();
kernel.Bind<IRepository<Goods>>().To<GoodsRepository>();
kernel.Bind<IRepository<Media>>().To<MediaRepository>();
kernel.Bind<IRepository<MediaType>>().To<MediaTypeRepository>();
kernel.Bind<IRepository<Ranking>>().To<RankingRepository>();
kernel.Bind<IRepository<Role>>().To<RoleRepository>();
kernel.Bind<IRepository<Sponsor>>().To<SponsorRepository>();
kernel.Bind<IRepository<State>>().To<StateRepository>();
kernel.Bind<IRepository<UserAccountInfo>>().To<UserAccountInfoRepository>();
kernel.Bind<IRepository<UserAction>>().To<UserActionRepository>();
kernel.Bind<IRepository<UserDeservesGoods>>().To<UserDeservesGoodsRepository>();
kernel.Bind<IRepository<UserGoods>>().To<UserGoodsRepository>();
kernel.Bind<IRepository<User>>().To<UserRepository>();
kernel.Bind<IUserService>().To<UserService>();
kernel.Bind<IAccountService>().To<AccountService>();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
here is my HomeController:
readonly IRepository<Ranking> repoRanking;
public HomeController(IRepository<Ranking> repoRanking)
{
this.repoRanking = repoRanking;
}
When I execute HomeController, I get follow exception:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Ninject.ActivationException: Error activating IRepository{Ranking}
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IRepository{Ranking} into parameter repoRanking of constructor of type HomeController
1) Request for HomeController
Suggestions:
1) Ensure that you have defined a binding for IRepository{Ranking}.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
What I doing wrong?
Have you created a default module where you set your bindings instead of in the register services method?
public class DefaultModule : NinjectModule {
public override void Load() {
Bind<IProductService>().To<ProductService>().InTransientScope();
}
}
and then in your Global.asax file do this:
protected override IKernel CreateKernel() {
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}