Can't build UWP in release mode - windows-10

I have a project that is working well in debug mode, but not working at all in release mode.
The solution contains 3 projects
Shared project
windows phone 8.1 project
UWP project
here is the error output
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : System.InvalidOperationException: Unable to generate a temporary class (result=1).
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0012: The type 'Windows.UI.Xaml.Visibility' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.UniversalApiContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0030: Cannot convert type 'Windows.UI.Xaml.Visibility' to 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0029: Cannot implicitly convert type 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]' to 'Windows.UI.Xaml.Visibility'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : at System.Xml.Serialization.Compiler.Compile(String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Hashtable assemblies, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, XmlMapping[] mappings, CompilerParameters parameters, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, String outputDir, String intermediateDir, List`1 wcfSerializers, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : at SerializationAssemblyGenerator.Program.Main(String[] args)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : Internal compiler error: One or more errors occurred.
The nuget packages I'm using are
"GoogleAnalyticsSDK": "1.2.12",
"HockeySDK.UWP": "4.0.0",
"HtmlAgilityPack": "1.4.9",
"Microsoft.ApplicationInsights": "1.0.0",
"Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
"Microsoft.ApplicationInsights.WindowsApps": "1.0.0",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"MvvmLightLibs": "5.1.1",
"Newtonsoft.Json": "8.0.3",
"WriteableBitmapEx": "1.5.0"
Update
I tried to add the Windows.Foundation.UniversalApiContract manually, but got this
Update 2
After I have unchecked the Compile with .Net Native tool chain feature, it worked.
Any way to build it using the .net native tool chain ?

I also hit a very similar issue. I had a type, let's say Foo, referencing a winmd type Windows.UI.Xaml.Visibility, see below.
public class Foo
{
public Windows.UI.Xaml.Visibility Visibility;
}
I got the exact same error at compile time when I tried to serialize an instance of type Foo using XmlSerializer. It seems that .Net Native tools have problem with generating XmlSerializer for types like Foo.
Here's my workaround. I created my own Visibility type, MyVisibility, and changed the existing Visibility field to a get only property (so that XmlSerializer would not serialize the property).
public class Foo
{
public Windows.UI.Xaml.Visibility Visibility
{
get
{
return (Visibility)myVisibility;
}
}
public MyVisibility myVisibility;
}
public enum MyVisibility
{
Visible = 0,
Collapsed = 1
}
Here's my test code for serializing a Foo instance,
public static void Test()
{
var foo = new Foo();
foo.myVisibility = MyVisibility.Collapsed;
var serializer = new XmlSerializer(typeof(Foo));
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, foo);
stream.Position = 0;
var foo1 = (Foo)serializer.Deserialize(stream);
Assert.True(foo.Visibility == foo1.Visibility);
}
}
Hope this helps.

Related

Why adding business controller class namespace in DNN makes module disappear?

I am trying to make a module searchable i DNN 9 so I created a class which implements ISearchable and overrides GetSearchItems.
following this documentation:
https://www.dnnsoftware.com/wiki/isearchable
public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
{
SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
ArrayList Documents = GetDocuments(ModInfo.ModuleID, ModInfo.PortalID, true);
foreach (var objDocument in Documents)
{
SearchItemInfo SearchItem;
{
var withBlock = (DocumentInfo)objDocument;
int UserId = Null.NullInteger;
// If IsNumeric(.CreatedByUser) Then
// UserId = Integer.Parse(.CreatedByUser)
// End If
UserId = withBlock.CreatedByUserID;
SearchItem = new SearchItemInfo(ModInfo.ModuleTitle + " - " + withBlock.Title, withBlock.Title, UserId, withBlock.CreatedDate, ModInfo.ModuleID, withBlock.ItemId.ToString(), withBlock.Title + " " + withBlock.Category, "ItemId=" + withBlock.ItemId.ToString());
SearchItemCollection.Add(SearchItem);
}
}
return SearchItemCollection;
}
But when I add the namespace of the class in the module manifest, the module disappears from the page (and indexing doesn't work).
The namespace of the class is ProjectName.ListaNews.ListaController
I have also tried ProjectName.ListaNews and changing it to DotNetNuke.Modules.ProjectName.ListaNews.ListaController
I have tried changing the business class controller both from module settings and from .dnn file.
Why adding business class namespace breaks my module and makes it disappear from the page?
-------------- EDIT ----------------
The business controller class name seems to be correct.
I checked the log file and found this error:
DotNetNuke.Framework.Reflection - ProjectName.ListaNews.ListaController, ProjectName.ListaNews
System.IO.FileNotFoundException: Could not load file or assembly 'ProjectName.ListaNews' or one of its dependencies.
Cannot find specified file.
File name: 'ProjectName.ListaNews'
in bin\ folder there is ListaNews.dll. I tried renaming it into ProjectName.ListaNews.dll but I had the same error (+ the site crash).
So I changed the business controller class to ListaNews.ListaController, ListaNews without ProjectName and it gave a new error:
DotNetNuke.Framework.Reflection - ListaNews.ListaController, ListaNews
System.TypeLoadException: Could not load type 'ListaNews.ListaController' from assembly 'ListaNews'.
Looks like it didn't find ListaController class.
I noticed ListaController.cs was not defined in .dnn file when I installed it.
I added this to the .dnn file
<component type="File">
other files definitions....
<files>
<file>
<name>ListaController.cs</name>
</file>
</files>
</component>
So I deleted and re-installed my module. Nothing changed though.
Does that give any hint?
Thanks
-------------- EDIT 2 ----------------
Since it was a namespace error I moved the controller class from ListaController.cs to View.ascx.cs and the previous error disappeared, so the class is probably visible now. But the module is still not visible (crashes) so i checked the log and it gave 2 very similiar errors:
1)
Message: Value cannot be null. Parameter name: type
StackTrace: in System.Activator.CreateInstance(Type type, Boolean nonPublic)
in System.Activator.CreateInstance(Type type)
in DotNetNuke.UI.Skins.Pane.IsVesionableModule(ModuleInfo moduleInfo)
in DotNetNuke.UI.Skins.Pane.InjectModule(ModuleInfo module)
in DotNetNuke.UI.Skins.Skin.InjectModule(Pane pane, ModuleInfo module)
InnerMessage: Value cannot be null. Parameter name: type
InnerStackTrace: at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at DotNetNuke.Services.Search.ModuleIndexer.GetModuleList(Int32 portalId)
I read System.Activator.CreateInstance documentation here:
https://learn.microsoft.com/it-it/dotnet/api/system.activator.createinstance?view=netcore-3.1#System_Activator_CreateInstance_System_Type_System_Boolean_
and actually CreateInstance has a constructor with type parameter,
But I think it is called in DNN compiled libraries and I can't see what is going on
I added this line in constructor
object instance = Activator.CreateInstance(typeof(ListaController));
and it logged this error:
Error Creating BusinessControllerClass
'ProjectName.ListaNews.ListaController, ProjectName.ListaNews' of
module(ProjectName.ListaNews) id=(577) in tab(45) and portal(0)
StackTrace:
at DotNetNuke.Services.Search.ModuleIndexer.ThrowLogError(ModuleInfo module,
Exception ex)
InnerMessage:Value cannot be null. Parameter name: type
InnerStackTrace:
at System.Activator.CreateInstance(Type type, Boolean nonPublic) at
system.Activator.CreateInstance(Type type) at
DotNetNuke.Services.Search.ModuleIndexer.GetModuleList(Int32 portalId)
I found this forum
https://www.dnnsoftware.com/forums/threadid/495897/scope/posts/help-with-rror-in-custom-module
so I added a parameterless constructor in my controller class but it didn't change anything
Why is type null in CreateInstance?
The value for businessControllerClass in the manifest must be in the format {FQCN}, {Assembly}. This is per The manifest schema
For your project, assuming the namespace is as you mentioned ProjectName.ListaNews.ListaController your assembly name is most likely ProjectName.ListaNews which would mean the proper value for the businessControllerClass is
ProjectName.ListaNews.ListaController, ProjectName.ListaNews
If that doesn't correct it, as Chris Hammond mentioned you can use the logs to get a more detailed error

Resolving a TypeReference to a TypeDefinition in Mono.Cecil fails with Assembly Resolution Error

I'm trying to get a Mono.Cecil TypeDefinition from a .NET type and not having any luck.
I'm using code like this:
var type = typeof(MarkdownMonster.AppConfiguration);
var a = AssemblyDefinition.ReadAssembly(type.Assembly.Location);
var tr = a.MainModule.Import(type); // this seems to work
var td = tr.Resolve(); // fails
but it fails with an assembly resolution error:
GetConfigurationPropertiesTest [0:29.990] Failed: Mono.Cecil.AssemblyResolutionException : Failed to resolve assembly: 'MarkdownMonster, Version=1.18.11.0, Culture=neutral, PublicKeyToken=null'
Mono.Cecil.AssemblyResolutionException : Failed to resolve assembly: 'MarkdownMonster, Version=1.18.11.0, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Westwind.TypeImporter.TypeParser.ParseObject(Type type, Boolean dontParseMembers)
The assembly is obviously there, since the TypeReference import seems to work and produces a valid TypeReference.
The assembly in question is an EXE, and just for kicks I renamed it to a DLL but that had no effect.
After a bit of back and forth experimenting I found one (ugly) solution is to create a custom type resolver and basically forcing a hard type reference into it. It seems Mono.Cecil is able to resolve transient dependencies once it's found the main assembly, but not the top level reference.
To make this work I basically pass in the already resolved assembly reference. In my case I know the only reference I will need to return will be the top level reference so I hard code this. A more realistic example will have to use AssemblyDefinition.ReadAssembly() to read an assembly off disk or from a stream.
Here's is the code to create the AssemblyResolver:
public class MonoAssemblyResolver : IAssemblyResolver
{
public AssemblyDefinition AssemblyDefinition;
public AssemblyDefinition Resolve(AssemblyNameReference name)
{
return AssemblyDefinition;
}
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
return AssemblyDefinition;
}
public void Dispose()
{
AssemblyDefinition = null;
}
}
Note the cheat to pass in an already resolved assembly reference.
To resolve I can now use the following code:
var a = AssemblyDefinition.ReadAssembly(type.Assembly.Location,
new ReaderParameters() { AssemblyResolver = resolver });
// assign the resolvedr
var resolver = new MonoAssemblyResolver();
resolver.AssemblyDefinition = a;
var tr = a.MainModule.Import(type: type);
var td = tr.Resolve(); // works now
This is crazy hacky, but can be adapted to be more generic (in my case not needed).
Still it would be much nicer if Mono.Cecil could automatically resolve the assembly - I don't understand why it's not finding the assembly in the first place since it lives in the current bin folder and the TypeReference can find it.
This is how it's normally done:
var assembly = #"c:\myassembly.dll";
var resolver = new DefaultAssemblyResolver();
// add .NET runtime dir for the sake of security
foreach (var dir in Directory.GetDirectories(RuntimeEnvironment.GetRuntimeDirectory(), "*", SearchOption.AllDirectories))
{
resolver.AddSearchDirectory(dir);
}
// add the assembly's directory
resolver.AddSearchDirectory(Path.GetDirectoryName(assembly));
var mod = AssemblyDefinition.ReadAssembly(assembly, new ReaderParameters { AssemblyResolver = resolver }).MainModule;
Regards

How to fix 'class name (...) does not match path (...)' error in unity

I'm writing a new AAR plugin in Android Studio. It contains only one simple java class:
package com.neitron.shareplugin;
public class ShareProvider {
private static final ShareProvider ourInstance = new ShareProvider();
public static ShareProvider getInstance() {
return ourInstance;
}
private ShareProvider() {
}
public String GetTestMesssage(int num)
{
return "Num is: " + num;
}
}
Then I've built it and copied the AAR file to Unity [2018.2.11f1]:
../Assets/Plugins/Android/shareplugin-release.aar
When I'm trying to build the project in unity it throws an exception:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_181\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2018.2.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\To
ols\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-
Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
Dex: Error converting bytecode to dex:
Cause: PARSE ERROR:
class name (com/neitron/shareplugin/R) does not match path
(com/Neitron/shareplugin/R.class)
...while parsing com/Neitron/shareplugin/R.class
PARSE ERROR:
class name (com/neitron/shareplugin/R) does not match path
(com/Neitron/shareplugin/R.class)
...while parsing com/Neitron/shareplugin/R.class
Dex: Error converting bytecode to dex:
Cause: PARSE ERROR:
class name (com/neitron/shareplugin/R$attr) does not match path
(com/Neitron/shareplugin/R$attr.class)
...while parsing com/Neitron/shareplugin/R$attr.class
PARSE ERROR:
class name (com/neitron/shareplugin/R$attr) does not match path
(com/Neitron/shareplugin/R$attr.class)
...while parsing com/Neitron/shareplugin/R$attr.class
And so on(
Is there any hacky trick I've missed. I already tried to clean the build in Android studio, checked all manifest files. There is no com.Neitron.sharepludin paths only com.neitron.shareplugin. Also, I've tried to create a blank plugin and blank test unity project and faced with the same issue.

MVC 5 Custom Html Helper extension issue

I'm trying to create a custom html helper class.
I have the below as a very simple start, complies fine:
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Mobile.HtmlHelpers
{
public static class RequestBox
{
public static HtmlString CascadeBoxFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, object htmlAttributes = null)
{
HtmlString html = (HtmlString)HtmlHelperInputExtensions.TextBoxFor(helper, expression);
return html;
}
// IHtmlContent html = HtmlHelperInputExtensions.TextBoxFor(htmlHelper, expression);
}
}
I am trying to call it and the system doesn't like it..
I can see it if I use:
#foreach (var item in Model.RequestModel.Requests)
{
#RequestBox.CascadeBoxFor(x=>item.EmployeeDescription)
}
But I get:
Severity Code Description Project File Line Suppression State
Error CS7036 There is no argument given that corresponds to the required formal parameter 'expression' of 'RequestBox.CascadeBoxFor<TModel, TValue>(HtmlHelper, Expression<Func<TModel, TValue>>, object)' Mobile..NET Framework 4.6.1
If I try suggestions of it being an extension and I should be able to use #Html.CascadeBoxFor(x => item.EmployeeDescription), I get:
Severity Code Description Project File Line Suppression State
Error CS1061 'IHtmlHelper<RequestPageModel>' does not contain a definition for 'CascadeBoxFor' and no extension method 'CascadeBoxFor' accepting a first argument of type 'IHtmlHelper<RequestPageModel>' could be found (are you missing a using directive or an assembly reference?) Mobile..NET Framework 4.6.1
Can anyone tell me what is missing here?

Loading assemblies dynamically using the AssemblyResolve Event fails at random

Following the example of the following KB article we have implemented the AssemblyResolve event in order to point .Net to the correct folder to load assemblies from: http://support.microsoft.com/kb/837908
This is our current implementation:
public static class AssemblyLoader
{
/// <summary>
/// A custom AssemblyResolver that will search for missing assemblies in the root and subfolders of the executing assembly
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
public static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string assemblyPath = string.Empty;
string assemblyFileName = string.Empty;
try
{
// This handler is called only when the common language runtime tries to bind to the assembly and fails.
string rootProbingPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
// Loop through the referenced assembly names.
assemblyFileName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
// Search for the filename in the root and subfolders of the rootProbingPath
string[] matchingAssemblies = Directory.GetFiles(rootProbingPath, assemblyFileName, SearchOption.AllDirectories);
// If a match is found, awesomeness was achieved!
if (matchingAssemblies.Length > 0)
assemblyPath = matchingAssemblies[0];
// Throw a clear exception when the assembly could not be found.
if (string.IsNullOrEmpty(assemblyPath))
throw new FileNotFoundException(string.Format("AssemblyLoader: Could not find assembly '{0}' in '{1}' or its subfolders.", assemblyFileName, rootProbingPath));
Console.WriteLine(string.Format("[" + DateTime.Now.ToString() + "] AssemblyLoader: Assembly '{0}' found at '{1}'", assemblyFileName, assemblyPath));
// Load the assembly from the specified path.
return Assembly.LoadFrom(assemblyPath, AppDomain.CurrentDomain.Evidence);
}
catch (Exception ex)
{
throw new Exception(string.Format("[" + DateTime.Now.ToString() + "] The assemblyloader could not load the assembly '{0}' from path '{1}': " + ex.Message, assemblyFileName, assemblyPath), ex);
}
}
}
We use this in all of our batch procedures which often run in parallel and using mostly the same assemblies.
Periodically a batch will crash leaving the following trail:
[26/04/2013 12:35:01] AssemblyLoader: Assembly
'COMPANY.DistributieOrderFacade.dll' found at
'C:\COMPANY_Batch\MDS\Executables\MDS\FACADE\COMPANY.DistributieOrderFacade.dll'
[26/04/2013 12:35:01] AssemblyLoader: Assembly
'COMPANY.DOCUMENTCENTERDOCS.dll' found at
'C:\COMPANY_Batch\MDS\Executables\MDS\CLIENT\COMPANY.DOCUMENTCENTERDOCS.dll'
26/04/2013 12:35:01: Create COMPANYDocument...in
queue:\rug.adroot\dfsroot\mds\Data\queue_new\ 26/04/2013 12:35:01
Could not load file or assembly 'COMPANY.DistributieOrderBRDA,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. General Exception (Exception from HRESULT: 0x80131500)
The assembly in the error is indeed located in one of the folders which the AssemblyLoader searches. And if I run the procedure again, it does succeed.
I've tried to see if the dll's are getting locked by using this assembly loader in two console apps and access the same dll's at the same time, but this did not seem to be a problem.
I should also mention that this is just a log from one of the batches. There are others, and it's rarely the same assembly that is not being loaded.
I don't know where to start looking for a solution next.
It was due to an update script that updated the dll's before each batch was running. When two batches were running at the same and there was a dll that needed updating, locks were occurring on the dll's which was causing the problem.
We've removed this script for a week now and haven't seen any problems yet. So our conclusion is that this was the problem.

Resources