CurlResources Init null reference exception - encryption

I have a WebAPI .NET Framework 4.8 application which needs to make a RESTful GET request to another, third-party web service using a specific cipher. I found a code sample using the CurlThin NuGet packages in a response to this question, and then perused the little documentation on CurlThin I could find, along with taking a peek at the open source library code on GitHub. All examples and documentation talk about the need for an initial call to
CurlResources.Init();
This call only needs to be made a single time at the initialization stage to copy the appropriate DLLs to the application output folder.
I placed this call in my web app's Application_Start method, but cannot get past a NullReferenceException:
I fully expect that I am overlooking something simple that's been staring back at me for hours. Any guidance would be much appreciated.

Related

System.Web.Services.Protocols.SoapException: <web service> has not been properly Initialized

We are having the following setup:
A custom DLL (VB.Net) has a web reference to a custom web service (ASP.Net, let's call it WebService0).
This custom DLL is instantiated by custom .Net EXE program, which make use of the exposed functions in the DLL, which in turn make calls to said WebService0.
e.g. .Net EXE Program calls DLL function which calls WebService0.
This setup works fine.
Now, take this setup to another computer, but instead of calling the DLL from a custom program like above, it is being called from yet another web service layer (let's call this one WebService1). And to test this WebService1 there is another .Net EXE program (not the same one mentioned above).
e.g. .Net EXE Program calls WebService1, which calls custom DLL function, which in turn calls WebService0.
For some reason, this setup throws the following exception:
System.Web.Services.Protocols.SoapException: WebService0 has not been properly Initialized
What could be happening? The cause does not seem to be evident. We have checked everything to the best of our knowledge.
We have searched the internet and there is barely any information about it that we could find.
Any help is very much appreciated.
I guess that your WebService1 is the source of this exception, when calling the DLL. And you do NOT have configuration embeded into DLL itself.
You've propably forgot to configure your WebService1 web.config system.serviceModel section.
Take a look at your .Net EXE Program (the first one) and it's App.Config (or YourExeName.exe.config) to see what system.serviceModel section looks like. I expect at least section to be filled.
Do the same in your WebService1/web.config/system.serviceModel
In case my guess is wrong and you've done this already, show us your configuration.

jax-rs url inside an ejb module

I created a tutorial that incorporates various components of J2EE in them. The app is an ear module that has an ejb project and a web project.
the project structure is
john-app
john-ear
john-ejb
john-web
the ejb project has a couple dao that perform basic crud operations using jpa. I'm trying to learn/understand jax-rs to gain a better understanding of json and handling json objects. the project is loosly based on
this project:
http://www.developer.com/java/creating-restful-web-services-with-jax-rs.html
so, i created my BookResource here and made it a stateless ejb. i have everything compiling and deploying without any obvious errors - other parts of the app work (the jpa stuff) but i can't get the jax-rs stuff to
work. i have a couple of"Books" that I created in my database and am wanting to test this by making a rest call through the browser.
so i deploy my .ear file in wildfly (v10) with no obvious errors, I see JNDI mappings for my EJB's...etc
initially, i'd like to be able to test this through my browser, but am not certain what url to use -- the class i have extending javax.ws.rs.core.Application has an application path of /rest and my
BookResource has a path of /library, and for getting all books from the library, the sub-resource is books. I've tried every combination of the url below,
http://localhost:8080/john-[app|ear|ejb|web]/rest/library/books
all to no avail. every call results in a 404 error, and the only time i got ANYTHING is when i tried john-web combination, it threw some ugly exception in the browser. so the questions is with a rest service living inside an ejb module within an ear, what should the url be given the above information. nothing i've tried
seems to work!??
I've not included any code samples to try and keep the explanation short -- i didn't want to include every java file in my little project, but can add anything as requested.
Thanks,
JG

understanding Trace listeners

I've recently just discovered the power of Tracing(no clue why it took this long). The theory and practice wasn't unknown to me just the resources available in .Net for doing so. Traditionally I would just log the parts of my programs that I needed to investigate until I got an answer to any problems or confusion. As of recent this task just doesn't give me enough information and is far too tedious as my application is too big now. There are not a lot of clear resources on much of this so I have a few questions:
If I add my own trace listener source to the trace.listeners collection will that trace listener receive the trace information that can be seen in the trace.axd page when tracing is enabled in the web.config of my application?
If so how would I go about creating said listener that can receive that input? I've created my own class that implements the trace listener class and I can't seem to get any other input to be logged other than my own? Have I misunderstood something?
If there is another way to log my application line by line without having to place my own logging, that would be very very helpful. Thank you.
If I add my own trace listener source to the trace.listeners
collection will that trace listener receive the trace information that
can be seen in the trace.axd page when tracing is enabled in the
web.config of my application?
You will be able to see anything written to Trace. The trace that is written to trace.axd is a bit different from a plain vanilla TraceSource, TraceListener, etc. The biggest difference is that it uses the Trace object, which is the .NET 1.1 way of doing trace. in .NET 2.0 & later, named TraceSources are introduced.
If you register a TraceSwitch, TraceSource and TraceListener in your web config, you can enable listening to any TraceSource that you know the name of, the WCF libraries are an example.
Other places document TraceSource and TraceListener and switches better than I can, e.g. http://blog.stephencleary.com/2010/12/simple-and-easy-tracing-in-net.html or https://msdn.microsoft.com/en-us/library/ms228984(v=vs.110).aspx
If so how would I go about creating said listener that can receive
that input? I've created my own class that implements the trace
listener class and I can't seem to get any other input to be logged
other than my own?
You can start by subclassing the ConsoleLogListener or a TextWriterTraceListener. This library has many tools for dealing with the rough edges of System.Diagnostics Trace. https://essentialdiagnostics.codeplex.com/
(Because the built in library has rough edges, expect to see a few people tell you to use some other logging library, there are many, but only System.Diagnostics is built in and always available)
If there is another way to log my application line by line without
having to place my own logging, that would be very very helpful.
This requires "code weaving" or Aspect oriented programming, where you use a tool to recompile your application and add things like logging or trace everywhere or where ever a certain attribute is found. PostSharp is one such application. Memory profiles sort of give you that line by line trace as a byproduct of showing you where your application is spending most of its time.

System.IO.FileNotFoundException when loading web service

I've a simple, if not primitive, C++/CLI .NET 2.0 class library. It is used in order to wrap some C++ legacy code for the Web Service. The following facts appear to be true:
Primitive C# test program calls class library and it works.
If class library does not refer to any modules of our code base, it works as well as part of the web service. That is, I load the web service and invoke the methods and receive proper response.
The same moment I replace the copied and pasted code by the calls from our code base libraries, the Web Service stops to load. I get System.IO.FileNotFoundException message.
The problem: I cannot find any place where the file name that couldn't be found is written.
I googled it and gave some permissions to some ASP.NET user on my computer. I copied all the DLLs of our libraries into the same directory where web service is installed. I searched in IIS logs, event logs, etc - no where could I find the name of the module that prevents the web service from coming up.
Any help on the matter would be greatly appreciated.
Boris
Make sure all the dependent DLLs are in the path (Path meaning not the directory where your assembly is, because ASP.net copies your assembly away into a temporary folder, but rather a directory that's included in the System path environment variable).
What calls are you replacing? Could it be the original code gracefully handles missing files (which may not even be important) and yours does not?
Add same rights to the iusr-account that you did to the asp.net-account.

Can Microsoft Code Contracts be used with an ASP.NET Website?

I'm currently using Microsoft Code Contracts in an ASP.NET MVC application without any issues but I can not seem to get it quite running in a basic ASP.NET Web site. I'm not entirely sure it was made to work with this type of project (although it shouldn't matter) so I wanted to bring it up to everyone.
I can compile the contracts just fine but the code skips over them since I'm assuming it hasn't been enabled through the Properties Page like you would do in other project types (ie ASP.NET MVC). I've gone to the property page of the project (which displays a dialog instead of the typical properties page) in my ASP.NET web site but it does not yield the same menu options and as such, doesn't have a section devoted to Code Contracts.
Also, I have Microsoft Code Contracts properly enabled within a class library project that I use to separate my business logic from the web site. The contracts compile fine but when a contract is violated, it throws a rather uninformative "Exception of type 'System.ExecutionEngineException' was thrown" error with no inner exception. My contract specifies a message to display upon violation but it is nowhere within the exception. It simply halts the execution of the process (which I believe is the default functionality for Microsoft Code Contracts).
I can't find anywhere that explicitly states that a particular project type can or can't (or shouldn't) be used with Contracts so I just wanted to see if anyone has had this issue.
Thanks for any help!
I had the same problem and this is how I solved it:
In the Referenced Class Libraries, right click -> properties -> code contracts.
Make sure "perform contract checking" is checked. I had mine set to "Full"
Contract Reference Assembly: make sure it is set to "Build"
Save your changes.
In the Referenced Class Libraries that have no contracts in their code, set the Contract Reference Assembly to "Do Not Build".
Then in the MVC project, have the Code Contracts "perform contract checking" checked. I had mine set to "Full".
Hope that helps somebody.
This sounds less like a Contracts and more like a build/config issue. Have you tried to deploy a prebuilt website? Are you sure that your website code sees the contracts code? Is the ASP.NET runtime using the CLR 4.0, or does it see the earlier Microsoft.Contracts.dll? Etc.

Resources