I'm Using C#.
I'm trying to create a web method in my .asmx file as follow:
[WebMethod]
public string MyWebMethod(Dictionary<string, string> parameters)
{
//...
}
And I got the following exception:
The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.
How can i fix it?
Thanks.
you can't use Dictionary direct but you can use list as parameters
and this link can help you to convert List to Dictionaryand continue your flow
C# Convert List to Dictionary
Related
I need to map IReadOnlyList<Person> to IReadOnlyList<PersonResponse> using Automapper.
IReadOnlyList<Person> personList = await _personRespository.getall();
var t = MyMapper.Mapper.Map<IReadOnlyList<PersonResponse>>(personList );
Mapping Class
CreateMap<IReadOnlyList<PersonResponse>, IReadOnlyList<Person>>().ReverseMap();
The error I get:
System.TypeLoadException: Method 'get_Item' in type
'Proxy_System.Collections.Generic.IReadOnlyList`1[[App.Application.Responses.PersonResponse,
App.Application, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]]34471389' from assembly 'AutoMapper.Proxies,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005'
does not have an implementation. at
System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() at
System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
Create an mapping between Person and PersonResponse, the concerned element types. Automapper would take care of collections themselves.
CreateMap<PersonResponse, Person>().ReverseMap();
You can read more Automapper and Collections here
i want to add watermark on videos in asp.net core,
i use this code :
NReco.VideoConverter.FFMpegConverter wrap = new FFMpegConverter();
wrap.Invoke("-i D:\\input.mp4 -i D:\\inputImage.png -filter_complex\"overlay=10:10\" D:\\Output.mp4");
but show this error, whats, problem ?
TypeLoadException: Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Using the latest RxUI v8 preview and Splat 2.0, in a UWP project referencing a .Net Standard 2.0 library, I can't register my view and viewmodel unless they reside in the same assembly.
I have:
Locator.CurrentMutable.RegisterLazySingleton(() => new HomeView(), typeof(IViewFor<HomeViewModel>));
But Splat gives an error:
DefaultViewLocator: Failed to find type named 'RxUI.UWP.Core.Views.HomeView, RxUI.UWP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
DefaultViewLocator: Failed to resolve service for type 'ReactiveUI.IViewFor`1[[RxUI.UWP.Core.ViewModels.HomeViewModel, RxUI.UWP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'.
DefaultViewLocator: Failed to find type named 'ReactiveUI.IRoutableView, ReactiveUI, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null'.
DefaultViewLocator: Failed to resolve service for type 'ReactiveUI.IViewFor`1[[ReactiveUI.IRoutableViewModel, ReactiveUI, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null]]'.
DefaultViewLocator: Failed to resolve view for view model type 'ReactiveUI.IRoutableViewModel'.
DefaultViewLocator: Failed to find type named 'RxUI.UWP.Core.Views.HomeView, RxUI.UWP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
So it's looking for the HomeView in the "Core" assembly, but it resides in the UWP project. Here's the structure...
I experienced the same issue with a similar environment as your. The issue resided in the DefaultViewLocator, since the view type is being renamed and resolved incorrectly to the viewmodel's assembly and namespace.
See lines 133-134 for how the view type name is determined:
var viewModelTypeName = viewModelType.AssemblyQualifiedName;
var proposedViewTypeName = this.ViewModelToViewFunc(viewModelTypeName);
Note: ViewModelToViewFunc is only a String.Replace that replaces "ViewModel" to "View" (see constructor).
To resolve this issue, my workaround was to create my own IViewLocator implementation, something like:
public class MyViewLocator : IViewLocator {
public MyViewModelLocator(Assembly viewAssembly, string viewNameSpace)
...
private IViewFor AttemptViewResolutionFor(Type viewModelType, string contract)
{
// proposed view type is now based on provided namespace + classname as modified by ViewModelToViewFunc
if (viewModelType == null) return null;
var viewModelTypeName = viewModelType.Name;
var proposedViewTypeName = _viewNamespace + "." + this.ViewModelToViewFunc(viewModelTypeName);
...
private IViewFor AttemptViewResolution(string viewTypeName, string contract)
{
try
{
// resolve view type in the assembly of the view, and not assembly of the viewmodel
var viewType = _viewAssembly.GetType(viewTypeName); // instead of Reflection.ReallyFindType(viewTypeName, throwOnFailure: false);
...
}
Finally, your custom viewlocator implementaiton must be registered with splat so that it overwrites DefaultViewLocator implementation:
Locator.CurrentMutable.RegisterConstant<IViewLocator>(new MyViewLocator(typeof(SplashView).Namespace, typeof(SplashView).Assembly));
http://pastebin.com/QaCCM2Zv
I have a config file in the above link, every time i try to access the section 'InventoryFactory' using this code:
var config = (ObjectFactoryConfiguration)ConfigurationManager.GetSection("InventoryFactory");
it returns an error:
An exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll but was not handled in user code
Additional information: An error occurred creating the configuration section handler for InventoryFactory: Could not load type 'WDG.ObjectFactory.ObjectFactoryConfiguration' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Any idea guys? Thanks :
If you haven't done so already you probably need to set up a custom configuration section handler to parse the "InventoryFactory" section into your "ObjectFactoryConfiguration" object. The error message indicates that the runtime is trying to load the "WDG.ObjectFactory.ObjectFactoryConfiguration" class from the "System.Configuration" assembly which wouldn't contain any of your custom classes.
...Also, you want to specify the assembly in the section, if you look at the line right above yours:<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> you can see at the end there the "log4net" assembly has been specified. Try putting the name of your assembly which contains the "ObjectFactoryConfiguration" class in the type attribute as well.
Why does var type = Type.GetType("System.Windows.Forms.TextBox"); return null?
I am trying to get the type of a TextBox type from a string.
You should include the full assembly name too:
var type = Type.GetType("System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Note the documentation on MSDN (emphasis mine):
The assembly-qualified name of the type to get. ... If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.
So only mscorlib and the Assembly.GetExecutingAssembly() can be resolved using the type name only, else you need the full assembly name too.
You should also include the assembly name and public tokens, etc:
var type = Type.GetType("System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");