ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.26k stars 118 forks source link

System.UnauthorizedAccessException - Documents and Settings folder #292

Open toddmcintosh opened 1 year ago

toddmcintosh commented 1 year ago

I'm trying to use IkvnmReference to compile a copy of Apache's FOP (fop.jar) using Ikvm 8.4.5. I've been getting multiple **The "IkvmReferenceItemPrepare" task failed unexpectedly** errors.

The latest one has to do with the application trying to acces the "Documents and Settings" folder to which access is denied in Windows 10. I've run Visual Studio in admin mode, and this still did not help.

Here's the error in the build output. Any advice would be appreciated.

Build started...
1>------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018: The "IkvmReferenceItemPrepare" task failed unexpectedly.
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018: System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings' is denied.
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at System.IO.FileSystemEnumerableIterator`1.AddSearchableDirsToStack(SearchData localSearchData)
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at System.IO.FileSystemEnumerableIterator`1.MoveNext()
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at IKVM.MSBuild.Tasks.IkvmReferenceItemPrepare.<ExpandPath>d__40.MoveNext() in D:\a\ikvm\ikvm\src\IKVM.MSBuild.Tasks\IkvmReferenceItemPrepare.cs:line 309
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at IKVM.MSBuild.Tasks.IkvmReferenceItemPrepare.ExpandCompile(IkvmReferenceItem item) in D:\a\ikvm\ikvm\src\IKVM.MSBuild.Tasks\IkvmReferenceItemPrepare.cs:line 269
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at IKVM.MSBuild.Tasks.IkvmReferenceItemPrepare.AssignMetadata(IkvmReferenceItem item) in D:\a\ikvm\ikvm\src\IKVM.MSBuild.Tasks\IkvmReferenceItemPrepare.cs:line 195
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at IKVM.MSBuild.Tasks.IkvmReferenceItemPrepare.AssignMetadata(IEnumerable`1 items) in D:\a\ikvm\ikvm\src\IKVM.MSBuild.Tasks\IkvmReferenceItemPrepare.cs:line 179
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at IKVM.MSBuild.Tasks.IkvmReferenceItemPrepare.Execute() in D:\a\ikvm\ikvm\src\IKVM.MSBuild.Tasks\IkvmReferenceItemPrepare.cs:line 161
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm\8.4.5\buildTransitive\netstandard2.0\IKVM.targets(37,9): error MSB4018:    at Microsoft.Build.CommandLine.OutOfProcTaskAppDomainWrapperBase.InstantiateAndExecuteTask(IBuildEngine oopTaskHostNode, LoadedType taskType, String taskName, String taskLocation, String taskFile, Int32 taskLine, Int32 taskColumn, AppDomainSetup appDomainSetup, IDictionary`2 taskParams)
1>Done building project "ClassLibrary1.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
toddmcintosh commented 1 year ago

As a followup I've tried a few different versions of the build (8.4, 8.2) and I'm getting the same error. I'm assuming this means it's an issue with my machine? If you could point me in the right direction I would appreciate it.

wasabii commented 1 year ago

Would help to see the IkvmReference line you're using. This is a very odd error.

wasabii commented 1 year ago

IkvmReference holds the path of the JAR or .class files in a metadata property named Compile. And that allows wildcards. So, you can for instance, do IkvmReference Include="foo*\.jar". If it detects a wildcard, it tries to expand it, which eventually requires enumerating file system entries. Which, it looks like is breaking for you. Which is odd: first, it's just a call to Directory.EnumerateFileSystemEntries, which is Runtime code (not ours). We wouldn't expect that to fail like this. But I guess it's possible.... if maybe it's trying to enumerate the entire C: drive or something. Which shouldn't happen unless you've actually configured IkvmReference to do so, and I don't see any valid reason to do this.

Like if you try to IkvmReference Include="C:\**" /> or something, I can imagine this happening. But that makes no sense to do. So I'd like to see what you're doing.

wasabii commented 1 year ago

Also, just so you know, given that FOP is a well published and maintained library, you can probably just access it through Maven.

IKVM.Maven.Sdk

toddmcintosh commented 1 year ago

I thought I was having issues with a networked drive so I ended up just putting it in the root of C.

    <ItemGroup>
        <IkvmReference Include="C:\fop.jar">
            <AssemblyName>Fop23</AssemblyName>
            <AssemblyVersion>2.3</AssemblyVersion>
            <AssemblyFileVersion>2.3</AssemblyFileVersion>
        </IkvmReference>
    </ItemGroup>
toddmcintosh commented 1 year ago

When I try to add IKVM.Maven.Sdk to an empty .NET Standard 2.0 class library, I get this build error:

Build started...
1>------ Build started: Project: ClassLibrary3, Configuration: Debug Any CPU ------
1>C:\Users\toddmcintosh1\.nuget\packages\ikvm.msbuild\8.4.4\buildTransitive\netstandard2.0\IKVM.MSBuild.targets(39,9): error : Could not locate IKVM.Runtime.dll.
1>Done building project "ClassLibrary3.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
toddmcintosh commented 1 year ago

Is there something being cached from before that is blocking the maven package from running?

wasabii commented 1 year ago

Oh. We don't support .NET standard at all. So that's one issue. Not even IkvmReference supports it.

wasabii commented 1 year ago

Can you try just putting the time someplace other than C?

toddmcintosh commented 1 year ago

So I was able to get the IKVM.Maven.Sdk package to load in my project, and the maven repo indeed has a Fop artifact, and I as able to use this strategy to load Fop into my .NET Core 6 project. Thank you so much for the direction, I had no experience with the world of Maven before! Cheers.

wasabii commented 1 year ago

Neato. Let's leave this issue open, as it does represent something that's broken. Some error with IkvmReference when using the C:\ drive directly.