DotNetNuke Action Menu Error - c#

I'm using DotNetNuke 5.3. I add one menu item in ModuleActionCollection. Then I add this page to Module definition also. But I got this error:
Error: is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException:
Object reference not set to an
instance of an object. --->
System.NullReferenceException: Object
reference not set to an instance of an
object. at
DotNetNuke.UI.Modules.ModuleHost.LoadModuleControl()
--- End of inner exception stack trace

Are you using the ModuleActions property from the IActionable interface? Can you attach a debugger to that property and see if the NullReferenceException is happening in there? If you remove the IActionable interface from the module, does that get rid of the error?
Can you provide your implementation of ModuleActions?

Related

How to fix Newtonsoft.Json.JsonConvert deserialize failure?

I have an asp.net WebAPI app. I'm returning files to the client in the Request.CreateResponse(,) second parameter as type Dictionary<string, List<System.Net.Http.StreamContent>>, where List<System.Net.Http.StreamContent>> contains all the files.
I'm deserializing the files at the client using the following:
var someContent = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<System.Net.Http.StreamContent>>>(result.Content.ReadAsStringAsync().Result);
This code throws the exception:
An unhandled exception of type
'Newtonsoft.Json.JsonSerializationException' occurred in
Newstonsoft.Json.dll.
Additional information: Unable to find a construction to use for type
System.Net.Http.StreamContent. A class should either have default
constructor, one constructor with arguments or a constructor marked
with the JsonConstructor attribute. Path 'myFiles[0].Headers'
Is there a different way to return actual files?

How can I indicate Unity use a specific constructor when resolves an instance

I'm building an asp.Net MVC application with Code First EntityFramework. I'm using Dependency Injection with Unity Container.
I have a context class like this
public partial class MyContext : DbContext
{
public MyContext()
: base("name=MyConnString")
{
Database.SetInitializer<MyContext>(null);
}
}
A Repository class like this:
public class Repository
{
public Repository(DbContext dataContext)
{
}
}
In Bootstrapper class I have this:
container.RegisterType<DbContext, MyContext>("DbContext",new HierarchicalLifetimeManager());
When I run the application, it throw this Exception:
The current type, System.Data.Common.DbConnection, is an abstract class > and cannot be constructed. Are you missing a type mapping?
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: System.InvalidOperationException: The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
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: System.InvalidOperationException: The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
After research I found that this error is because Unity uses the most verbose constructor by default.
I need use the second constructor, but I don't know how configure Unity
Have you any idea?
You're looking for InjectionConstructor:
public partial class MyContext : DbContext
{
[InjectionConstructor]
public MyContext()
: base("name=MyConnString")
{
Database.SetInitializer<MyContext>(null);
}
}
You may also find this useful reading: https://msdn.microsoft.com/en-us/library/ff650802.aspx

WPF Prism Request Navigate activation error

Referring the StockTraderRI, I created a popup region in my shell
infBehaviors:RegionPopupBehaviors.CreatePopupRegionWithName="{x:Static inf:RegionNames.SecondaryRegion}"
In the module I am trying to load the view to the popup
_regionManager.RequestNavigate(RegionNames.SecondaryRegion, new Uri("/OrderDetailsView", UriKind.Relative));
OrderDetailsView is a view within OrderDetailsModule. At this point I am getting the below error
Activation error occurred while trying to get instance of type Object, key "OrderDetailsView"
Stack trace looks like below
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 103
at Prism.Regions.RegionNavigationContentLoader.CreateNewRegionItem(String candidateTargetContract)
Any ideas what i might be doing wrong?
You must register your objects for navigation. If you are using Prism 6 you must use Container.RegisterTypeForNavigation<OrderDetailsView>();
If using v5 or less you must use container.RegisterType(typeof(object), typeof(OrderDetailsView), "OrderDetailsView");
EDIT: If using MEF, you must provide the view name in the Export Attribute:
[Export("OrderDetailsView")]
public class OrderDetailsView : UserControl
{ ... }

Problem with c# webservice, referencing a method and a type

I have run into a bit of a problem, well not sure if it is a problem, but would like some advice.
I have developed a c# webservice in vs2010 and when I debug the service i get this error in my browser
The XML element 'VoucherResponse' from namespace 'http://test.org/' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
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: System.InvalidOperationException: The XML element 'VoucherResponse' from namespace 'test.org' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Now looking at my code in at the actual class "VoucherResponse" i have,
public class VoucherResponse : AResponse
{
public Voucher Voucher { get; set; }
}
And the Voucher object looks like this
public class Voucher
{
public string PIN { get; set; }
public string Serial { get; set; }
public string Batch { get; set; }
}
Now in one of my web methods I return the VoucherResponse and I am assuming that this error occurs when it is reflected through and checked.
Has anyone had a similar problem with this before, or can anyone give me some advice on this?
Thanks
I found another case that raises the error! Here's my code:
[WebMethod]
public CheckUpdateResponse CheckUpdate()
{
...
}
Ok, let me explain: CheckUpdateResponse is a structure I defined in my code, CheckUpdate() is a method. So, in the WSDL .NET add automatically a Response suffix to the method name CheckUpdate.
Et voilĂ : it finds a duplicate element and gives the error "Change the method's message name using WebMethodAttribute..."
Solution? I renamed the returned type from CheckUpdateResponse to CheckUpdateResult and now everything works fine!
I hope this will help someone! I lost a lot of time on this...
Apparently, SOAP cannot handle methods that have the same name as their return type.
You can fix it by reading the error, and acting accordingly:
public class VoucherResponse
{
[WebMethod(MessageName="TheVoucher")]
public Voucher Voucher{get; set;}
}
I had the same issue, but in my case; the application that I developed is web service client, so I don't have control on changing the WSDL\Schema.
The problem was that I had one web service with 17 operations, all of them are returning the same complex type, I got the mentioned error due to deserialization of the return type, because .Net is wrapping the return type for each output, and the serializer is throwing error:
The XML element 'XYZ' from namespace 'ABC' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
Solution:
I opened Reference.cs file, removed all wappered return type generated classes, and kept only one, then changed its class name to be generic, not related to the operation, it worked for me.

Get Object reference when using context rewrite path

I get this error when i have this in my codebehind: if(Page.User.Identity.IsAuthenticated)
System.NullReferenceException: Object reference not set to an instance of an object.
This error show when i use context.RewritePath method
http://localhost/page.apsx?id=22 --> http://localhost/hello-world/
Page.User.Identity.IsAuthenticated return True when i go to page.aspx?id=22 but i get
System.NullReferenceException: Object reference not set to an instance of an object.
error when i go to /hello-world/ url.
If the url.Contains("List") then rewrite the url like this:
context.RewritePath(Utility.WebRoot + "List/Add.aspx", false);
My rewriter is not more complicate then that.

Categories