I am trying to upgrade my application to ASP.NET Core 3.1 and I am getting the below error when I am trying to Resolves a type using the type activator cache,
Below is the sample code,
The TypeActivatorCache isnt supported in ASP.NET Core 3.1 anymore and hence I have used the below code to replicate what it does in a nutshell, https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.Core/src/Infrastructure/TypeActivatorCache.cs
private TInstance CreateInstance<TInstance>(
IServiceProvider serviceProvider,
Type implementationType)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
if (implementationType == null)
{
throw new ArgumentNullException(nameof(implementationType));
}
var createFactory = _typeActivatorCache.GetOrAdd(implementationType, _createFactory);
return (TInstance)createFactory(serviceProvider, arguments: null);
}
System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' while attempting to activate 'Microsoft.AspNetCore.Hosting.DefaultApplicationInsightsServiceConfigureOptions'.'
Any help would be much appreciated,
Related
I had a working project with very dated NuGet package set for WebJob and storage. After a massive upgrade, I'm having three errors in this block only:
private static void Main()
{
var config = new JobHostConfiguration();
config.Queues.MaxDequeueCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDequeueCount"]);
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["MaxPollingInterval"]));
config.Queues.BatchSize = Convert.ToInt32(ConfigurationManager.AppSettings["BatchSize"]); ;
config.NameResolver = new QueueNameResolver();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
host.RunAndBlock();
}
Errors:
Error CS0246: The type or namespace name 'JobHostConfiguration' could not be found (are you missing a using directive or an assembly reference?) \Program.cs:11
Error CS7036: There is no argument given that corresponds to the required formal parameter 'options' of 'JobHost.JobHost(IOptions<JobHostOptions>, IJobHostContextFactory)' \Program.cs:23
Error CS1061: 'JobHost' does not contain a definition for 'RunAndBlock' and no accessible extension method 'RunAndBlock' accepting a first argument of type 'JobHost' could be found (are you missing a using directive or an assembly reference?) \Program.cs:24
All the helps and questions are showing .Net Core code. I'm on .Net Framework 4.7.2. How do I go about setting up this code in old framework?
If you want to Azure WebJob SDK V3, the JobHostConfiguration and JobHost have been removed. In version V3, the host is an implementation of IHost. For more details, please refer to here and here. Besides, please note that in version 3, you need to explicitly install the Storage binding extension required by the WebJobs SDK.
For example (Queue trigger in version 3)
#Install package Microsoft.Azure.WebJobs.Extensions.Storage 3.x
static async Task Main()
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage(a => {
a.BatchSize = 8;
a.NewBatchThreshold = 4;
a.MaxDequeueCount = 4;
a.MaxPollingInterval = TimeSpan.FromSeconds(15);
});
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
According to other asked questions like this one, I did many doings to prevent this request expired message but there is no solution for my issue.
In the long run I recognized that the message appears when I call a service method inside a controller which run on form action!
Here is my codes samples with some descriptions:
My route:
Route::post('Material/{id}', 'MaterialController#updateMaterial')->name('updateMaterial');
Material Controller Constructor:
public function __construct(CustomService $srv)
{
$this->middleware('admin')->only(['updateMaterial']);
$this->srv= $srv;
}
srv is a protected attribute in MaterialController class.
updateMaterial Method:
public function updateMaterial($id,Request $request)
{
$this->validate($request, [...]);
$material = $this->srv->updateMaterial($request, $id);
if ($material)
return view('panel._materials.edit-material')
->with('material', $material)
->with('success', 1);
}
I also have a provider for CustomService with name CustomServiceProvider and here is the register method of the provider:
public function register()
{
$this->app->bind(CustomService::class,function($app){
return new CustomService();
});
}
and I registered it as a provider in config/app.php.
So when I return something before calling service updateMaterial method, it's OK. but when the method runs, the issue appears!
I don'n have any idea about!
Update:
And here is updateMaterial of CustomService:
public function updateMaterial($request, $id)
{
$material = Material::find($id);
if (!$material)
return false;
if ($request->has('unit'))
$material->unit = $request['unit'];
if ($request->has('price'))
$material->price = $request['price'];
if ($request->has('type'))
$material->type = $request['type'];
if ($request->has('is_active'))
$material->is_active = $request['is_active'];
$material->updated_at = Carbon::now();
$material->save();
return $material;
}
I also create a new project with Laravel 5.5.0 and without adding any complexity I just added a post route and call it in form action, but nothing changed!
This is just an issue for Windows users on Local Environment. I suffered a lot with this also when on Windows. Once you deploy to your production server, you won't have any issue at all.
It's important to note that this is not an issue with Laravel 5.5 version only. I first saw this issue in version 5.2.
I think a good fix for this would maybe be using something like Homestead or Vessel from Fideloper. Honestly I only suffered this problem when using Windows.
I want to register a goal/conversion on my Sitecore 6.5 site using the API rather than a 'thank-you' page.
I've seen this question about how to do it Sitecore OMS - achieving a goal on a form submission but the answer relates to the API prior to Sitecore 6.5 where it was overhauled quite significantly.
Has anyone done this? Or has this functionality been intentionally removed?
Have you tried something like
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
PageEventData eventData = new PageEventData("My Goal Name");
eventData.Data = "this is some event data.";
VisitorDataSet.PageEventsRow pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(eventData);
Sitecore.Analytics.Tracker.Submit();
}
}
That should register the goal on the currentpage, but not before you decide to in your code
You can also use a modified version of the code which references the Goal Item by its GUID:
if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
PageEventItem goal = new PageEventItem(Sitecore.Context.Database.GetItem("GOALGUID"));
VisitorDataSet.PageEventsRow pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goal);
Sitecore.Analytics.Tracker.Submit();
}
Make sure you have deployed and published your goal and or goal category too as the code will fail otherwise.
I am using StageWebView to show a local HTML page (using file://). I want to call a function in my flex mobile project to be called from a JS function. Using ExternalInterface, I have
in Flex -
ExternalInterface.addCallback("myFunction",myFunc);
in JS -
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
function showAlert()
{
alert("Going to call AS function");
thisMovie("ShowLocalHTML").myFunction("Hello");
return false;
}
I am getting "Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime." when trying to run the application.
And my project targets Android platform. And I have Mozilla, Chrome installed on my desktop - although I am not user if that is relevant to the problem.
Please help in resolving this issue.
Since I am new to Flex and AS it took me a while to understand the problem. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html and http://sean.voisen.org/blog/2010/10/making-the-most-of-stagewebview/. What it means is External Interface is not available for use with StageWebView in AIR for android.
True, but you still can communicate js <> air if you are using an ANE solution. Check here https://github.com/myflashlab/webView-ANE I'm the coder of this ANE by the way! :)
I have a simple application with an web service created with Apache CXF. This application works when I run the server and the client (as Java applications). When I try to access the application /services URL which is mapped in web.xml, Tomcat gives me 404 error. When I run the project I receive:
org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://sendmessage/}SendMessage
If anyone has any hints related to this error I would be glad to hear them. (I searched google and couldn't find something relevant to my situation)
Thank you!
I had same error, mine was related to namespace which were different in wsdl and webservice. So I changed them to the same.
WSDL:
<wsdl:definitions name=""
targetNamespace="http://www.example.org/yourservice/"
Webservice class:
#WebService(targetNamespace = "http://www.example.org/yourservice/",
.........
Even I had a similar issue.
Fixed it by updating the jaxws:endpoint.
I added the serviceName (mapping to the name present in the WSDL file) with the name space as defined in the "targetNamespace" defined in the wsdl:definitions tag.
<jaxws:endpoint id=".." implementor="..." serviceName="s:SERVICE_NAME_IN_WSDL"
xmlns:s="TARGET_NAME_SPACE_WSDL_DEFINTIONS"></jaxws:endpoint>
edited(06Jul)
Also, I have today that, with Apache CXF 3.0.5 version this issue is not coming;
But with Apache CXF 3.1 version, this is coming.
ServiceConstructionException can occur at various stages when cxf compares the provided service, port and binding name with the wsdl it has already parsed. In this case ( and in most cases) it looks to be namespace issue.
{http://sendmessage/}SendMessage is either not present in parsed wsdl or the service name does not match with the QName present in the WSDL. There are other cases as well where binding or port does not match, one might receive the same exception. Following is a code snippit from org.apache.cxf.wsdl11.WSDLServiceFactory.create() method where it all happens.
If things are not clear why exactly it is happening your best bet is to debug this piece of code and see where it is failing and what is there in parsed wdsl definition (com.ibm.wsdl.DefinitionImpl in wsdl4j.jar).
javax.wsdl.Service wsdlService = definition.getService(serviceName);
if (wsdlService == null) {
if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName))
&& (!PartialWSDLProcessor.isBindingExisted(definition, serviceName))
&& (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
try {
Map<QName, PortType> portTypes = CastUtils.cast(definition.getPortTypes());
String existPortName = null;
PortType portType = null;
for (QName existPortQName : portTypes.keySet()) {
existPortName = existPortQName.getLocalPart();
if (serviceName.getLocalPart().contains(existPortName)) {
portType = portTypes.get(existPortQName);
break;
}
}
WSDLFactory factory = WSDLFactory.newInstance();
ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
Binding binding = PartialWSDLProcessor.doAppendBinding(definition,
existPortName, portType, extReg);
definition.addBinding(binding);
wsdlService = PartialWSDLProcessor.doAppendService(definition,
existPortName, extReg, binding);
definition.addService(wsdlService);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
} else {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
PS: I know this issue was opened back in 2011 but recently I faced the same issue and was able to resolve it. I hope it help others who are facing this issue.
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for port {http://localhost:9990/project/wsdl/targetName}targetNameSoap12.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:179)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:428)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:548)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
Fixed problem, define at annotation #WebService(targetNameSpace = "targetNameSoap12") in your web service interface and in the contract WSDL.
For exemplo:
...
<wsdl:service name='targetName'>
<wsdl:port binding='tns:targetNameSoap12' name='targetNameSoap12'>
...